| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/i18n", |
| 4 |
"./MappedTextBox", |
| 5 |
"dojo/i18n!./nls/validate" |
| 6 |
], function(declare, i18n, MappedTextBox){ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
var RangeBoundTextBox = declare("dijit.form.RangeBoundTextBox", MappedTextBox, { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
rangeMessage: "", |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
rangeCheck: function( primitive, constraints){ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
return ("min" in constraints? (this.compare(primitive,constraints.min) >= 0) : true) && |
| 31 |
("max" in constraints? (this.compare(primitive,constraints.max) <= 0) : true); |
| 32 |
}, |
| 33 |
|
| 34 |
isInRange: function( ){ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
return this.rangeCheck(this.get('value'), this.constraints); |
| 40 |
}, |
| 41 |
|
| 42 |
_isDefinitelyOutOfRange: function(){ |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
var val = this.get('value'); |
| 47 |
if(val == null){ return false; } |
| 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 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
return this.inherited(arguments) && !this._isDefinitelyOutOfRange(); |
| 66 |
}, |
| 67 |
|
| 68 |
isValid: function( isFocused){ |
| 69 |
|
| 70 |
return this.inherited(arguments) && |
| 71 |
((this._isEmpty(this.textbox.value) && !this.required) || this.isInRange(isFocused)); |
| 72 |
}, |
| 73 |
|
| 74 |
getErrorMessage: function( isFocused){ |
| 75 |
|
| 76 |
var v = this.get('value'); |
| 77 |
if(v != null && v !== '' && (typeof v != "number" || !isNaN(v)) && !this.isInRange(isFocused)){ |
| 78 |
return this.rangeMessage; |
| 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 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
return RangeBoundTextBox; |
| 100 |
}); |