Dojo small example (34) ValidationTextBox with Ajax asynchronous verification

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:

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5781 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.