2012-10-22 45 views
2

有沒有辦法阻止Dojo驗證onBlur上的文本框?Dojo驗證

var textbox = new ValidationTextBox({ 
    placeholder : "search", 
    name : "userQuery", 
    required : true, 
    missingMessage : "Please enter search term", 
    onBlur : function(){ 
      //function to stop onBlur validation 
    } 
}, textboxNode); 

回答

1

從技術上來說,是的。但我不確定它何時會驗證它是否不在布爾。

var textbox = new ValidationTextBox({ 
    placeholder : "search", 
    name : "userQuery", 
    required : true, 
    missingMessage : "Please enter search term", 
    validator: function(value, constraints){ 
    if (this.hasOwnProperty("focused")) { //true if textbox is loaded 
     if (!this.focused) { // if textbox not focused (onblur) 
     return true; // considered valid 
     } 
    } 
    return value !== ""; // test if value is empty 
    } 
}, textboxNode); 
+0

我upvoted,但我建議不要在驗證器回調中使用'textbox'。 「this」無論如何都會引用ValidationTextBox,所以你可以使用this.hasOwnProperty – Layke

+0

謝謝,更新。 – raykendo