EasyUI Forum
October 18, 2025, 09:00:33 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Empty Datebox when wrong date is entered  (Read 12235 times)
leela
Newbie
*
Posts: 29


View Profile Email
« 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.' 
   }
});
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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){
//...
}
})
Logged
iamjxc
Jr. Member
**
Posts: 80


View Profile
« Reply #2 on: July 22, 2014, 11:25:57 PM »

validate 在输入字符时就会调用, 所以清空的代码不能放在这里.

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

如果非要清空, 可以用:
var tb = $("#cc").combo("textbox");
tb.bind("blur", function(evt){
    ...
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!