Changed inside the input of the spinner

Changed inside the input of the spinner

klermannklermann Posts: 246Questions: 62Answers: 1

Hello Allan, do you have suggestion to get the text that is changed inside the input of the spinner? I tried some javascript lines but not right!
`// Input spinner
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
define( ['jquery', 'datatables', 'datatables-editor'], factory );
}
else if ( typeof exports === 'object' ) {
module.exports = function ($, dt) {
if ( ! $ ) { $ = require('jquery'); }
factory( $, dt || $.fn.dataTable || require('datatables') );
};
}
else if ( jQuery ) {
factory( jQuery, jQuery.fn.dataTable );
}
}(function( $, DataTable ) {
'use strict';

if ( ! DataTable.ext.editorFields ) {
    DataTable.ext.editorFields = {};
}
var _fieldTypes = DataTable.Editor ?
    DataTable.Editor.fieldTypes :
    DataTable.ext.editorFields;

_fieldTypes.spinner = {
    create: function ( conf ) {
        var that = this;

        conf._input = $('<div id=' + conf.id + '>' +
                        '<input id="receitaFixaQuant" type="text" class="form-control repetirQuant" value="1" />' +
                    '</div>'
                )
                .attr( $.extend( {}, conf.attr ) );

            $('.repetirQuant', conf._input)
            .asSpinner().attr( $.extend( {}, conf.attr || {} ) );


            console.log($('.repetirQuant', conf._input).text());
             $('.spinnerUi-up', conf._input).click(function () {        

                 var attrVal = $('#receitaFixaQuant').val();
                 if ( conf._enabled ) {
                     that.set( conf.name, $('#receitaFixaQuant').attr(attrVal));
                }

                return false;
            } );

        return conf._input[0];
    },

    get: function ( conf ) {
        return conf._input.children('input').val();
    },

    set: function ( conf, val ) {
    },

    disable: function ( conf ) {
        conf._input.data("spinnerUi").disable();
    },
    enable: function ( conf ) {
        conf._input.data("spinnerUi").enable();
    },
    inst: function ( conf ) {
        return conf._input.data("spinnerUi");
    }
};
}));`

Answers

  • allanallan Posts: 48,301Questions: 1Answers: 6,970 Site admin

    I'm afraid I don't know what spinner you are referring to?

    Allan

  • klermannklermann Posts: 246Questions: 62Answers: 1
    edited September 2017

    A count of numbers picked up by an input, inside the plugin I can not get the text ie the numbers that are generated in the input

    https://jqueryui.com/spinner/

  • allanallan Posts: 48,301Questions: 1Answers: 6,970 Site admin

    I'd suggest you simply use:

    {
      label: ...,
      name: ...,
      attr: {
        type: 'number'
      }
    

    to use a native HTML5 number picker rather than using jQuery UI.

    However, to get the value from input the input, you'd need to refer to the jQUery UI documentation.

    Allan

  • klermannklermann Posts: 246Questions: 62Answers: 1
    edited September 2017

    Allan with this plugin I'm already having the numbering inside the input, I can perfectly get the field as a counter, I just can not get it to send to the server inside the object. Here's how I'm trying to do and I'm not having success!

    this example returns empty and not the counter number

    get: function ( conf ) { console.log(conf._input.attr('val')); return conf._input.val(); },

  • allanallan Posts: 48,301Questions: 1Answers: 6,970 Site admin

    The jQuery UI documentation I linked to recommends using $( ".selector" ).spinner( "value" ); - have you tried that?

  • klermannklermann Posts: 246Questions: 62Answers: 1

    This example I sent you is to see what I am doing, in the plugin I sent you I am capturing the numbers normally, but I can not send them to the server, because the value is empty.

    `create: function ( conf ) {
    var that = this;

        conf._input = $('<div id=' + conf.id + '>' +
                        '<input id="receitaFixaQuant" type="text" class="form-control repetirQuant" value="1" />' +
                    '</div>'
                )
                .attr( $.extend( {}, conf.attr ) );
    
            $('.repetirQuant', conf._input)
            .asSpinner().attr( $.extend( {}, conf.attr || {} ) );
    
            console.log($('.repetirQuant', conf._input).text());
             $('.spinnerUi-up', conf._input).click(function () {       
    
                 var attrVal = $('#receitaFixaQuant').val();
                 if ( conf._enabled ) {
                     that.set( conf.name, $('#receitaFixaQuant').attr(attrVal));
                }
    
                return false;
            } );
    
        return conf._input[0];
    }`
    

    When sending the data this field is empty, and I need to capture the value of it, which is the number!

    get: function ( conf ) { console.log(conf._input.attr('val')); return conf._input.val(); },

  • klermannklermann Posts: 246Questions: 62Answers: 1

    I solved here:

    return $('#receitaFixaQuant', conf._input).val();

    Thanks!

Sign In or Register to comment.