Debian Codegraph @

dijit/form/RangeBoundTextBox.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/i18n", // i18n.getLocalization
4 "./MappedTextBox",
5 "dojo/i18n!./nls/validate"
6 ], function(declare, i18n, MappedTextBox){
7
8 // module:
9 // dijit/form/RangeBoundTextBox
10
11
12 var RangeBoundTextBox = declare("dijit.form.RangeBoundTextBox", MappedTextBox, {
13 // summary:
14 // Base class for textbox form widgets which defines a range of valid values.
15
16 // rangeMessage: String
17 // The message to display if value is out-of-range
18 rangeMessage: "",
19
20 /*=====
21 // constraints: RangeBoundTextBox.__Constraints
22 constraints: {},
23 ======*/
24
25 rangeCheck: function(/*Number*/ primitive, /*dijit/form/RangeBoundTextBox.__Constraints*/ constraints){
26 // summary:
27 // Overridable function used to validate the range of the numeric input value.
28 // tags:
29 // protected
30 return ("min" in constraints? (this.compare(primitive,constraints.min) >= 0) : true) &&
31 ("max" in constraints? (this.compare(primitive,constraints.max) <= 0) : true); // Boolean
32 },
33
34 isInRange: function(/*Boolean*/ /*===== isFocused =====*/){
35 // summary:
36 // Tests if the value is in the min/max range specified in constraints
37 // tags:
38 // protected
39 return this.rangeCheck(this.get('value'), this.constraints);
40 },
41
42 _isDefinitelyOutOfRange: function(){
43 // summary:
44 // Returns true if the value is out of range and will remain
45 // out of range even if the user types more characters
46 var val = this.get('value');
47 if(val == null){ return false; } // not yet valid enough to compare to
48 var outOfRange = false;
49 if("min" in this.constraints){
50 var min = this.constraints.min;
51 outOfRange = this.compare(val, ((typeof min == "number") && min >= 0 && val != 0) ? 0 : min) < 0;
52 }
53 if(!outOfRange && ("max" in this.constraints)){
54 var max = this.constraints.max;
55 outOfRange = this.compare(val, ((typeof max != "number") || max > 0) ? max : 0) > 0;
56 }
57 return outOfRange;
58 },
59
60 _isValidSubset: function(){
61 // summary:
62 // Overrides `dijit/form/ValidationTextBox._isValidSubset()`.
63 // Returns true if the input is syntactically valid, and either within
64 // range or could be made in range by more typing.
65 return this.inherited(arguments) && !this._isDefinitelyOutOfRange();
66 },
67
68 isValid: function(/*Boolean*/ isFocused){
69 // Overrides dijit/form/ValidationTextBox.isValid() to check that the value is also in range.
70 return this.inherited(arguments) &&
71 ((this._isEmpty(this.textbox.value) && !this.required) || this.isInRange(isFocused)); // Boolean
72 },
73
74 getErrorMessage: function(/*Boolean*/ isFocused){
75 // Overrides dijit/form/ValidationTextBox.getErrorMessage() to print "out of range" message if appropriate
76 var v = this.get('value');
77 if(v != null /* and !undefined */ && v !== '' && (typeof v != "number" || !isNaN(v)) && !this.isInRange(isFocused)){ // don't check isInRange w/o a real value
78 return this.rangeMessage; // String
79 }
80 return this.inherited(arguments);
81 },
82
83 postMixInProperties: function(){
84 this.inherited(arguments);
85 if(!this.rangeMessage){
86 this.messages = i18n.getLocalization("dijit.form", "validate", this.lang);
87 this.rangeMessage = this.messages.rangeMessage;
88 }
89 }
90 });
91 /*=====
92 RangeBoundTextBox.__Constraints = declare(null, {
93 // min: Number
94 // Minimum signed value. Default is -Infinity
95 // max: Number
96 // Maximum signed value. Default is +Infinity
97 });
98 =====*/
99 return RangeBoundTextBox;
100 });