PDA

View Full Version : NumberField - how to toggle 'allowNegative' ?



mschwartz
13 Apr 2009, 5:45 AM
I have a form that looks like this:

[] Signed (checkbox)
[_________________] (numberfield id = 'nf')

I want to do something like:



cb.on('check', function(cb, checked) { Ext.getCmp('nf').setAllowNegative(checked); } })


for obvious reasons.

Solution?



if(this.allowDecimals){
allowed += this.decimalSeparator;
}
if(this.allowNegative){
allowed += "-";
}
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');


Is in NumberField.js

So:



cb.on('check', function(cb, checked) {
var nf = Ext.getCmp('nf');
var allowed = nf.baseChars+'';
nf.allowNegative = checked;
if(nf.allowDecimals){
allowed += nf.decimalSeparator;
}
if(nf.allowNegative){
allowed += "-";
}
nf.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
});


Maybe all properties of instantiated widgets should be alterable after instantiation?

mschwartz
13 Apr 2009, 6:36 AM
Ext.override(Ext.form.Numberfield, {
setAllowNegative: function(flag) {
this.allowNegative = flag;
var allowed = this.baseChars+'';
if(this.allowDecimals){
allowed += this.decimalSeparator;
}
if(this.allowNegative){
allowed += "-";
}
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
}
});

mschwartz
13 Apr 2009, 6:48 AM
Something for the core developers to consider:

http://ejohn.org/blog/javascript-getters-and-setters/