| | 193 | validate: function(/*Boolean*/ isFocused){ |
| | 194 | // summary: |
| | 195 | // Called by oninit, onblur, and onkeypress. |
| | 196 | // description: |
| | 197 | // Show missing or invalid messages if appropriate, and highlight textbox field. |
| | 198 | var isValid = this.isValid(isFocused); |
| | 199 | this.state = isValid ? "" : "Error"; |
| | 200 | this._setStateClass(); |
| | 201 | dijit.setWaiState(this.focusNode, "invalid", isValid ? "false" : "true"); |
| | 202 | var message = isValid ? "" : this._missingMsg; |
| | 203 | if(this._message !== message){ |
| | 204 | this._message = message; |
| | 205 | dijit.hideTooltip(this.domNode); |
| | 206 | if(message){ |
| | 207 | dijit.showTooltip(message, this.domNode, this.tooltipPosition); |
| | 208 | } |
| | 209 | } |
| | 210 | return isValid; |
| | 211 | }, |
| | 212 | |
| | 213 | isValid: function(/*Boolean*/ isFocused){ |
| | 214 | // summary: Whether or not this is a valid value |
| | 215 | return (!this.required || !/^\s*$/.test(this.value)); |
| | 216 | }, |
| | 217 | |
| | 218 | reset: function(){ |
| | 219 | // summary: Overridden so that the state will be cleared. |
| | 220 | this.inherited(arguments); |
| | 221 | dijit.hideTooltip(this.domNode); |
| | 222 | this.state = ""; |
| | 223 | this._setStateClass(); |
| | 224 | delete this._message; |
| | 225 | }, |
| | 226 | |
| | 227 | postMixInProperties: function(){ |
| | 228 | // summary: set the missing message |
| | 229 | this.inherited(arguments); |
| | 230 | this._missingMsg = dojo.i18n.getLocalization("dijit.form", "validate", |
| | 231 | this.lang).missingMessage; |
| | 232 | }, |
| | 233 | |