define([ "dojo/_base/declare", "dijit/form/ValidationTextBox", "dojo/request"], function(declare, ValidationTextBox, request) {return declare("AjaxValidationTextBox", [ValidationTextBox ], {ajaxUrl: null, ajaxLock: false, // Hook to prevent infinite loop ajaxResult: false, oldValue: null, // Used to compare whether the input value has changed changed: false , // Identification: Whether the input value has changed isValid: function() {var widget = this; this.changed = false; if (this.get('value') != this.oldValue) {this.changed = true; } if (!this.ajaxLock && this.ajaxUrl && this.get('value') && !this.focused && this.changed) {this.oldValue = this.get('value'); this.ajaxLock = true; request(widget.ajaxUrl + encodeURIComponent( widget.get('value') ), {handleAs:'text' }).then(function(result) {widget.ajaxResult = (result == "true"? true: false) ; widget.validate(); // will call the isValid method to re-validate the entered value, and pop up tip widget.ajaxLock = false; });} return this.ajaxResult;} });});
Usage: