EasyUI Forum

General Category => General Discussion => Topic started by: leela on May 30, 2014, 06:59:38 AM



Title: Empty Datebox when wrong date is entered
Post by: leela on May 30, 2014, 06:59:38 AM
i, i am trying to use this code to validate my dateboxes. It works fine and displays a message when the user enters wrong date, but is there a way we can empty the datebox field along with the message. Because if the user ignores the messages, the form is still being submitted with wrong value. please advise.

I tried the following, but it empties the datebox field as soon as I enter a character.
Is there a better solution?

Code:
$.extend($.fn.validatebox.defaults.rules, {
   validDate: { 
      validator: function(value, element){ 
         var date = $.fn.datebox.defaults.parser(value);
         var s = $.fn.datebox.defaults.formatter(date);
         if(s==value){
            return true;
         }else{
            $(element[0]).datebox('setValue', '');
            return false;
         }
      }, 
      message: 'Please enter a valid date.' 
   }
});


Title: Re: Empty Datebox when wrong date is entered
Post by: stworthy on May 31, 2014, 07:09:46 AM
If you are using the 'form' plugin to submit a form, returning false in 'onSubmit' event will prevent from submitting this form.
Code:
$('#ff').form('submit',{
url:url,
onSubmit:function(){
return $(this).form('validate');  // return false if any invalid fields exist.
},
success:function(result){
//...
}
})


Title: Re: Empty Datebox when wrong date is entered
Post by: iamjxc on July 22, 2014, 11:25:57 PM
validate 在输入字符时就会调用, 所以清空的代码不能放在这里.

建议不清空错误的信息, 而是留给用户自己去纠正.

如果非要清空, 可以用:
var tb = $("#cc").combo("textbox");
tb.bind("blur", function(evt){
    ...
});