]>
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 // dijit/form/RangeBoundTextBox
11 var RangeBoundTextBox
= declare ( "dijit.form.RangeBoundTextBox" , MappedTextBox
, {
13 // Base class for textbox form widgets which defines a range of valid values.
15 // rangeMessage: String
16 // The message to display if value is out-of-range
20 // constraints: RangeBoundTextBox.__Constraints
24 rangeCheck : function ( /*Number*/ primitive
, /*dijit/form/RangeBoundTextBox.__Constraints*/ constraints
){
26 // Overridable function used to validate the range of the numeric input value.
29 return ( "min" in constraints
? ( this . compare ( primitive
, constraints
. min
) >= 0 ) : true ) &&
30 ( "max" in constraints
? ( this . compare ( primitive
, constraints
. max
) <= 0 ) : true ); // Boolean
33 isInRange : function ( /*Boolean*/ /*===== isFocused =====*/ ){
35 // Tests if the value is in the min/max range specified in constraints
38 return this . rangeCheck ( this . get ( 'value' ), this . constraints
);
41 _isDefinitelyOutOfRange : function (){
43 // Returns true if the value is out of range and will remain
44 // out of range even if the user types more characters
45 var val
= this . get ( 'value' );
46 if ( val
== null ){ return false ; } // not yet valid enough to compare to
47 var outOfRange
= false ;
48 if ( "min" in this . constraints
){
49 var min
= this . constraints
. min
;
50 outOfRange
= this . compare ( val
, (( typeof min
== "number" ) && min
>= 0 && val
!= 0 ) ? 0 : min
) < 0 ;
52 if (! outOfRange
&& ( "max" in this . constraints
)){
53 var max
= this . constraints
. max
;
54 outOfRange
= this . compare ( val
, (( typeof max
!= "number" ) || max
> 0 ) ? max
: 0 ) > 0 ;
59 _isValidSubset : function (){
61 // Overrides `dijit/form/ValidationTextBox._isValidSubset()`.
62 // Returns true if the input is syntactically valid, and either within
63 // range or could be made in range by more typing.
64 return this . inherited ( arguments
) && ! this . _isDefinitelyOutOfRange ();
67 isValid : function ( /*Boolean*/ isFocused
){
68 // Overrides dijit/form/ValidationTextBox.isValid() to check that the value is also in range.
69 return this . inherited ( arguments
) &&
70 (( this . _isEmpty ( this . textbox
. value
) && ! this . required
) || this . isInRange ( isFocused
)); // Boolean
73 getErrorMessage : function ( /*Boolean*/ isFocused
){
74 // Overrides dijit/form/ValidationTextBox.getErrorMessage() to print "out of range" message if appropriate
75 var v
= this . get ( 'value' );
76 if ( v
!= null /* and !undefined */ && v
!== '' && ( typeof v
!= "number" || ! isNaN ( v
)) && ! this . isInRange ( isFocused
)){ // don't check isInRange w/o a real value
77 return this . rangeMessage
; // String
79 return this . inherited ( arguments
);
82 postMixInProperties : function (){
83 this . inherited ( arguments
);
84 if (! this . rangeMessage
){
85 this . messages
= i18n
. getLocalization ( "dijit.form" , "validate" , this . lang
);
86 this . rangeMessage
= this . messages
. rangeMessage
;
90 applyTextDir : function ( /*===== element, text =====*/ ){
92 // The function overridden in the _BidiSupport module,
93 // originally used for setting element.dir according to this.textDir.
94 // In this case does nothing.
102 RangeBoundTextBox.__Constraints = declare(null, {
104 // Minimum signed value. Default is -Infinity
106 // Maximum signed value. Default is +Infinity
109 return RangeBoundTextBox
;