git.ithinksw.org
/
extjs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git]
/
src
/
widgets
/
form
/
NumberField.js
diff --git
a/src/widgets/form/NumberField.js
b/src/widgets/form/NumberField.js
index
e132013
..
12b9222
100644
(file)
--- a/
src/widgets/form/NumberField.js
+++ b/
src/widgets/form/NumberField.js
@@
-1,5
+1,5
@@
/*!
/*!
- * Ext JS Library 3.
2.2
+ * Ext JS Library 3.
3.0
* Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
* Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
@@
-24,50
+24,65
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
* @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
*/
fieldClass: "x-form-field x-form-num-field",
* @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
*/
fieldClass: "x-form-field x-form-num-field",
+
/**
* @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
*/
allowDecimals : true,
/**
* @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
*/
allowDecimals : true,
+
/**
* @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
*/
decimalSeparator : ".",
/**
* @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
*/
decimalSeparator : ".",
+
/**
* @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
*/
decimalPrecision : 2,
/**
* @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
*/
decimalPrecision : 2,
+
/**
* @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
*/
allowNegative : true,
/**
* @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
*/
allowNegative : true,
+
/**
* @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
*/
minValue : Number.NEGATIVE_INFINITY,
/**
* @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
*/
minValue : Number.NEGATIVE_INFINITY,
+
/**
* @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
*/
maxValue : Number.MAX_VALUE,
/**
* @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
*/
maxValue : Number.MAX_VALUE,
+
/**
* @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
*/
minText : "The minimum value for this field is {0}",
/**
* @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
*/
minText : "The minimum value for this field is {0}",
+
/**
* @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
*/
maxText : "The maximum value for this field is {0}",
/**
* @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
*/
maxText : "The maximum value for this field is {0}",
+
/**
* @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
* if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
*/
nanText : "{0} is not a valid number",
/**
* @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
* if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
*/
nanText : "{0} is not a valid number",
+
/**
* @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
*/
baseChars : "0123456789",
/**
* @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
*/
baseChars : "0123456789",
+
+ /**
+ * @cfg {Boolean} autoStripChars True to automatically strip not allowed characters from the field. Defaults to <tt>false</tt>
+ */
+ autoStripChars: false,
// private
// private
- initEvents : function(){
+ initEvents : function()
{
var allowed = this.baseChars + '';
if (this.allowDecimals) {
allowed += this.decimalSeparator;
var allowed = this.baseChars + '';
if (this.allowDecimals) {
allowed += this.decimalSeparator;
@@
-75,7
+90,12
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
if (this.allowNegative) {
allowed += '-';
}
if (this.allowNegative) {
allowed += '-';
}
- this.maskRe = new RegExp('[' + Ext.escapeRe(allowed) + ']');
+ allowed = Ext.escapeRe(allowed);
+ this.maskRe = new RegExp('[' + allowed + ']');
+ if (this.autoStripChars) {
+ this.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi');
+ }
+
Ext.form.NumberField.superclass.initEvents.call(this);
},
Ext.form.NumberField.superclass.initEvents.call(this);
},
@@
-90,7
+110,7
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
getErrors: function(value) {
var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
getErrors: function(value) {
var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
- value =
value ||
this.processValue(this.getRawValue());
+ value =
Ext.isDefined(value) ? value :
this.processValue(this.getRawValue());
if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
return errors;
if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
return errors;
@@
-104,22
+124,22
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
var num = this.parseValue(value);
var num = this.parseValue(value);
- if
(num < this.minValue)
{
+ if
(num < this.minValue)
{
errors.push(String.format(this.minText, this.minValue));
}
errors.push(String.format(this.minText, this.minValue));
}
- if
(num > this.maxValue)
{
+ if
(num > this.maxValue)
{
errors.push(String.format(this.maxText, this.maxValue));
}
return errors;
},
errors.push(String.format(this.maxText, this.maxValue));
}
return errors;
},
- getValue : function(){
+ getValue : function()
{
return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
},
return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
},
- setValue : function(v){
+ setValue : function(v)
{
v = this.fixPrecision(v);
v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
v = this.fixPrecision(v);
v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
@@
-130,7
+150,7
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
* Replaces any existing {@link #minValue} with the new value.
* @param {Number} value The minimum value
*/
* Replaces any existing {@link #minValue} with the new value.
* @param {Number} value The minimum value
*/
- setMinValue : function(value){
+ setMinValue : function(value)
{
this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
},
this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
},
@@
-138,30
+158,37
@@
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
* Replaces any existing {@link #maxValue} with the new value.
* @param {Number} value The maximum value
*/
* Replaces any existing {@link #maxValue} with the new value.
* @param {Number} value The maximum value
*/
- setMaxValue : function(value){
+ setMaxValue : function(value)
{
this.maxValue = Ext.num(value, Number.MAX_VALUE);
},
// private
this.maxValue = Ext.num(value, Number.MAX_VALUE);
},
// private
- parseValue : function(value){
+ parseValue : function(value)
{
value = parseFloat(String(value).replace(this.decimalSeparator, "."));
return isNaN(value) ? '' : value;
},
value = parseFloat(String(value).replace(this.decimalSeparator, "."));
return isNaN(value) ? '' : value;
},
- // private
- fixPrecision : function(value){
+ /**
+ * @private
+ *
+ */
+ fixPrecision : function(value) {
var nan = isNaN(value);
var nan = isNaN(value);
- if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
- return nan ? '' : value;
+
+ if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
+ return nan ? '' : value;
}
}
+
return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
},
return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
},
- beforeBlur : function(){
+ beforeBlur : function()
{
var v = this.parseValue(this.getRawValue());
var v = this.parseValue(this.getRawValue());
- if(!Ext.isEmpty(v)){
+
+ if (!Ext.isEmpty(v)) {
this.setValue(v);
}
}
});
this.setValue(v);
}
}
});
-Ext.reg('numberfield', Ext.form.NumberField);
\ No newline at end of file
+
+Ext.reg('numberfield', Ext.form.NumberField);