EasyUI Forum
November 03, 2025, 08:30:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: cannot clear value numberbox with clear method  (Read 8767 times)
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« 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.
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 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);
Logged
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #2 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?
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!