]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/RangeBoundTextBox.js.uncompressed.js
1 define("dijit/form/RangeBoundTextBox", [
2 "dojo/_base/declare", // declare
3 "dojo/i18n", // i18n.getLocalization
5 ], function(declare
, i18n
, MappedTextBox
){
8 var MappedTextBox = dijit.form.MappedTextBox;
12 // dijit/form/RangeBoundTextBox
14 // Base class for textbox form widgets which defines a range of valid values.
17 dijit.form.RangeBoundTextBox.__Constraints = function(){
19 // Minimum signed value. Default is -Infinity
21 // Maximum signed value. Default is +Infinity
27 return declare("dijit.form.RangeBoundTextBox", MappedTextBox
, {
29 // Base class for textbox form widgets which defines a range of valid values.
31 // rangeMessage: String
32 // The message to display if value is out-of-range
36 // constraints: dijit.form.RangeBoundTextBox.__Constraints
40 rangeCheck: function(/*Number*/ primitive
, /*dijit.form.RangeBoundTextBox.__Constraints*/ constraints
){
42 // Overridable function used to validate the range of the numeric input value.
45 return ("min" in constraints
? (this.compare(primitive
,constraints
.min
) >= 0) : true) &&
46 ("max" in constraints
? (this.compare(primitive
,constraints
.max
) <= 0) : true); // Boolean
49 isInRange: function(/*Boolean*/ /*===== isFocused =====*/){
51 // Tests if the value is in the min/max range specified in constraints
54 return this.rangeCheck(this.get('value'), this.constraints
);
57 _isDefinitelyOutOfRange: function(){
59 // Returns true if the value is out of range and will remain
60 // out of range even if the user types more characters
61 var val
= this.get('value');
62 var isTooLittle
= false;
63 var isTooMuch
= false;
64 if("min" in this.constraints
){
65 var min
= this.constraints
.min
;
66 min
= this.compare(val
, ((typeof min
== "number") && min
>= 0 && val
!=0) ? 0 : min
);
67 isTooLittle
= (typeof min
== "number") && min
< 0;
69 if("max" in this.constraints
){
70 var max
= this.constraints
.max
;
71 max
= this.compare(val
, ((typeof max
!= "number") || max
> 0) ? max
: 0);
72 isTooMuch
= (typeof max
== "number") && max
> 0;
74 return isTooLittle
|| isTooMuch
;
77 _isValidSubset: function(){
79 // Overrides `dijit.form.ValidationTextBox._isValidSubset`.
80 // Returns true if the input is syntactically valid, and either within
81 // range or could be made in range by more typing.
82 return this.inherited(arguments
) && !this._isDefinitelyOutOfRange();
85 isValid: function(/*Boolean*/ isFocused
){
86 // Overrides dijit.form.ValidationTextBox.isValid to check that the value is also in range.
87 return this.inherited(arguments
) &&
88 ((this._isEmpty(this.textbox
.value
) && !this.required
) || this.isInRange(isFocused
)); // Boolean
91 getErrorMessage: function(/*Boolean*/ isFocused
){
92 // Overrides dijit.form.ValidationTextBox.getErrorMessage to print "out of range" message if appropriate
93 var v
= this.get('value');
94 if(v
!== null && v
!== '' && v
!== undefined && (typeof v
!= "number" || !isNaN(v
)) && !this.isInRange(isFocused
)){ // don't check isInRange w/o a real value
95 return this.rangeMessage
; // String
97 return this.inherited(arguments
);
100 postMixInProperties: function(){
101 this.inherited(arguments
);
102 if(!this.rangeMessage
){
103 this.messages
= i18n
.getLocalization("dijit.form", "validate", this.lang
);
104 this.rangeMessage
= this.messages
.rangeMessage
;
108 _setConstraintsAttr: function(/*Object*/ constraints
){
109 this.inherited(arguments
);
110 if(this.focusNode
){ // not set when called from postMixInProperties
111 if(this.constraints
.min
!== undefined){
112 this.focusNode
.setAttribute("aria-valuemin", this.constraints
.min
);
114 this.focusNode
.removeAttribute("aria-valuemin");
116 if(this.constraints
.max
!== undefined){
117 this.focusNode
.setAttribute("aria-valuemax", this.constraints
.max
);
119 this.focusNode
.removeAttribute("aria-valuemax");
124 _setValueAttr: function(/*Number*/ value
, /*Boolean?*/ priorityChange
){
126 // Hook so set('value', ...) works.
128 this.focusNode
.setAttribute("aria-valuenow", value
);
129 this.inherited(arguments
);
132 applyTextDir: function(/*===== element, text =====*/){
134 // The function overridden in the _BidiSupport module,
135 // originally used for setting element.dir according to this.textDir.
136 // In this case does nothing.