EasyUI Forum
May 17, 2024, 06:45:21 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: datebox validation  (Read 22238 times)
ui_user
Newbie
*
Posts: 6


View Profile
« on: December 17, 2013, 04:21:20 AM »

Hi All,

This a very basic question in have regarding datebox.

How to validate the datebox value by adding a validator? I wanted to keep the datebox as editable. So I am able to input any values(like aphanumeric etc) to the date field.
So using validator i wanted to check whether it is a actual date entered in mm/dd/yyyy format.

Thanks and Regards
user
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: December 17, 2013, 06:19:17 PM »

Extend a validate rule and assign it to the datebox.
Code:
<input class="easyui-datebox" required validType="...">
Logged
ui_user
Newbie
*
Posts: 6


View Profile
« Reply #2 on: December 17, 2013, 11:57:44 PM »

Thank you for the reply.

I tried it out that way. My code is as follows

$.extend($.fn.validatebox.defaults.rules, {
   validDate: { 
            validator: function(value){                
                var date= $.fn.datebox.defaults.parser(value);
           alert(isNaN(Date.parse(date)));
      return !(isNaN(Date.parse(date)));
            }, 
            message: 'Please enter a valid date.' 
        }
});

<input type="text" class="easyui-datebox" validType="validDate"/>

But even if i enter alphabets and tab out, i am not getting the invalid message. This is the same case if i enter a value like 45/89/75 etc. but the alert is coming which i placed inside validator.

Could you please tell, what mistake i have done?

Regards
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: December 18, 2013, 04:03:52 AM »

Try this:
Code:
$.extend($.fn.validatebox.defaults.rules, { 
validDate: { 
validator: function(value){ 
var date = $.fn.datebox.defaults.parser(value);
var s = $.fn.datebox.defaults.formatter(date);
return s==value;
}, 
message: 'Please enter a valid date.' 
}
});
Logged
ui_user
Newbie
*
Posts: 6


View Profile
« Reply #4 on: December 18, 2013, 05:14:40 AM »

It worked..
Thank you so much.
Logged
leela
Newbie
*
Posts: 29


View Profile Email
« Reply #5 on: May 23, 2014, 10:23:59 AM »

Try this:
Code:
$.extend($.fn.validatebox.defaults.rules, { 
validDate: { 
validator: function(value){ 
var date = $.fn.datebox.defaults.parser(value);
var s = $.fn.datebox.defaults.formatter(date);
return s==value;
}, 
message: 'Please enter a valid date.' 
}
});


Hi, 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
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!