tvheadend/vendor/ext-3.4.1/docs/source/NumberField.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

208 lines
8.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-form-NumberField-method-constructor'><span id='Ext-form-NumberField'>/**
</span></span> * @class Ext.form.NumberField
* @extends Ext.form.TextField
* Numeric text field that provides automatic keystroke filtering and numeric validation.
* @constructor
* Creates a new NumberField
* @param {Object} config Configuration options
* @xtype numberfield
*/
Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
<span id='Ext-form-NumberField-cfg-stripCharsRe'> /**
</span> * @cfg {RegExp} stripCharsRe @hide
*/
<span id='Ext-form-NumberField-cfg-maskRe'> /**
</span> * @cfg {RegExp} maskRe @hide
*/
<span id='Ext-form-NumberField-cfg-fieldClass'> /**
</span> * @cfg {String} fieldClass The default CSS class for the field (defaults to &quot;x-form-field x-form-num-field&quot;)
*/
fieldClass: &quot;x-form-field x-form-num-field&quot;,
<span id='Ext-form-NumberField-cfg-allowDecimals'> /**
</span> * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
*/
allowDecimals : true,
<span id='Ext-form-NumberField-cfg-decimalSeparator'> /**
</span> * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
*/
decimalSeparator : &quot;.&quot;,
<span id='Ext-form-NumberField-cfg-decimalPrecision'> /**
</span> * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
*/
decimalPrecision : 2,
<span id='Ext-form-NumberField-cfg-allowNegative'> /**
</span> * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
*/
allowNegative : true,
<span id='Ext-form-NumberField-cfg-minValue'> /**
</span> * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
*/
minValue : Number.NEGATIVE_INFINITY,
<span id='Ext-form-NumberField-cfg-maxValue'> /**
</span> * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
*/
maxValue : Number.MAX_VALUE,
<span id='Ext-form-NumberField-cfg-minText'> /**
</span> * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to &quot;The minimum value for this field is {minValue}&quot;)
*/
minText : &quot;The minimum value for this field is {0}&quot;,
<span id='Ext-form-NumberField-cfg-maxText'> /**
</span> * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to &quot;The maximum value for this field is {maxValue}&quot;)
*/
maxText : &quot;The maximum value for this field is {0}&quot;,
<span id='Ext-form-NumberField-cfg-nanText'> /**
</span> * @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 &quot;{value} is not a valid number&quot;)
*/
nanText : &quot;{0} is not a valid number&quot;,
<span id='Ext-form-NumberField-cfg-baseChars'> /**
</span> * @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
*/
baseChars : &quot;0123456789&quot;,
<span id='Ext-form-NumberField-cfg-autoStripChars'> /**
</span> * @cfg {Boolean} autoStripChars True to automatically strip not allowed characters from the field. Defaults to &lt;tt&gt;false&lt;/tt&gt;
*/
autoStripChars: false,
<span id='Ext-form-NumberField-method-initEvents'> // private
</span> initEvents : function() {
var allowed = this.baseChars + '';
if (this.allowDecimals) {
allowed += this.decimalSeparator;
}
if (this.allowNegative) {
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);
},
<span id='Ext-form-NumberField-method-getErrors'> /**
</span> * Runs all of NumberFields validations and returns an array of any errors. Note that this first
* runs TextField's validations, so the returned array is an amalgamation of all field errors.
* The additional validations run test that the value is a number, and that it is within the
* configured min and max values.
* @param {Mixed} value The value to get errors for (defaults to the current field value)
* @return {Array} All validation errors for this field
*/
getErrors: function(value) {
var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
if (value.length &lt; 1) { // if it's blank and textfield didn't flag it then it's valid
return errors;
}
value = String(value).replace(this.decimalSeparator, &quot;.&quot;);
if(isNaN(value)){
errors.push(String.format(this.nanText, value));
}
var num = this.parseValue(value);
if (num &lt; this.minValue) {
errors.push(String.format(this.minText, this.minValue));
}
if (num &gt; this.maxValue) {
errors.push(String.format(this.maxText, this.maxValue));
}
return errors;
},
<span id='Ext-form-NumberField-method-getValue'> getValue : function() {
</span> return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
},
<span id='Ext-form-NumberField-method-setValue'> setValue : function(v) {
</span> v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, &quot;.&quot;));
v = this.fixPrecision(v);
v = isNaN(v) ? '' : String(v).replace(&quot;.&quot;, this.decimalSeparator);
return Ext.form.NumberField.superclass.setValue.call(this, v);
},
<span id='Ext-form-NumberField-method-setMinValue'> /**
</span> * Replaces any existing {@link #minValue} with the new value.
* @param {Number} value The minimum value
*/
setMinValue : function(value) {
this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
},
<span id='Ext-form-NumberField-method-setMaxValue'> /**
</span> * Replaces any existing {@link #maxValue} with the new value.
* @param {Number} value The maximum value
*/
setMaxValue : function(value) {
this.maxValue = Ext.num(value, Number.MAX_VALUE);
},
<span id='Ext-form-NumberField-method-parseValue'> // private
</span> parseValue : function(value) {
value = parseFloat(String(value).replace(this.decimalSeparator, &quot;.&quot;));
return isNaN(value) ? '' : value;
},
<span id='Ext-form-NumberField-method-fixPrecision'> /**
</span> * @private
*
*/
fixPrecision : function(value) {
var nan = isNaN(value);
if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
return nan ? '' : value;
}
return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
},
<span id='Ext-form-NumberField-method-beforeBlur'> beforeBlur : function() {
</span> var v = this.parseValue(this.getRawValue());
if (!Ext.isEmpty(v)) {
this.setValue(v);
}
}
});
Ext.reg('numberfield', Ext.form.NumberField);
</pre>
</body>
</html>