EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Opan Mustopah on January 17, 2015, 10:10:15 AM



Title: cannot clear value numberbox with clear method
Post by: Opan Mustopah on January 17, 2015, 10:10:15 AM
hello again.

i got a little problem again.
why i can't clear value or text numberbox element with clear method?
here is my code, i'm sure nothing's wrong with code:
Code:
$('#nw').numberbox({
      onChange:function(newValue,oldValue){
        var nw_val = newValue;
        var gw_val = $('#gw').numberbox('getValue');
        if (nw_val != "" && gw_val != ""){
          if (!isNaN(gw_val) && !isNaN(nw_val)){
            if (parseFloat(nw_val) > parseFloat(gw_val)){
              $(this).numberbox('clear');
              $.messager.alert('Info',"NW must be lower than GW",'info');
            }
          }
        }
      }
    });


it should clear numberbox value and text. can you tell me maybe where is wrong in my code?

many thanks for the answer.


Title: Re: cannot clear value numberbox with clear method
Post by: jarry on January 17, 2015, 07:17:19 PM
Please try to override the 'setValue' method for the numberbox component.
Code:
(function($){
$.extend($.fn.numberbox.methods, {
setValue: function(jq, value){
return jq.each(function(){
var target = this;
var state = $.data(target, 'numberbox');
var opts = state.options;
value = opts.parser.call(target, value);
var text = opts.formatter.call(target, value);
opts.value = value;
$(target).textbox('setText', text).textbox('setValue', value);
})
}
});
})(jQuery);


Title: Re: cannot clear value numberbox with clear method
Post by: Opan Mustopah on January 18, 2015, 01:17:10 AM
thanks jarry for that code, it works now.
but why i must extend setValue method when this plugin is inherited from textbox?