EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on July 28, 2016, 09:31:10 PM



Title: numberbox, numberspinner, textbox etc onBeforeChange
Post by: devnull on July 28, 2016, 09:31:10 PM
Hi;

I need to prevent changes to numberbox and numberspinner based on doing some validation on the new value and old value and this CANNOT be done using a validRule as the formulas maybe complex and involve many variables.

What I really need is an onBeforeChange(nv,ov) method that allows me to return false to prevent the change.

Thanks


Title: Re: numberbox, numberspinner, textbox etc onBeforeChange
Post by: stworthy on July 29, 2016, 02:10:05 AM
The code below shows how to add the 'onBeforeSetValue' event to the numberbox.
Code:
(function($){
var setValue = $.fn.numberbox.methods.setValue;
$.extend($.fn.numberbox.methods, {
setValue: function(jq, value){
return jq.each(function(){
var opts = $(this).numberbox('options');
if (opts.onBeforeSetValue){
var oldValue = $(this).numberbox('getValue');
if (opts.onBeforeSetValue.call(this, value) == false){
setValue($(this), oldValue);
return;
}
}
setValue($(this), value);
})
}
})
})(jQuery);

$(function(){
$('#n1').numberbox({
onBeforeSetValue: function(value){
console.log('onBeforeSetValue:'+value);
return value>10;
},
onChange: function(value){
console.log('onChange:'+value)
}
})
})