EasyUI Forum
September 14, 2025, 01:40:39 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: Databox validator  (Read 9618 times)
bakkers
Newbie
*
Posts: 21


View Profile Email
« on: October 08, 2015, 06:08:36 AM »

Hello

I use Databox to allow users to select a date, however i want to restrict the date range. I found this example http://www.jeasyui.com/demo/main/index.php?plugin=DateBox& and Restrict Date. But i can't get it to work.

This is how my code looks now

Code:
<input class="easyui-datebox" id="returDatoArbejdstid" data-options="formatter:myformatter,parser:myparser" value="18-09-2015"></input>

And i would like to be able to add validator to the data-options instead of using the method shown in the Restrict Date on the site.

Is this posible?

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


View Profile Email
« Reply #1 on: October 08, 2015, 06:24:11 PM »

Please try this:
Code:
<input class="easyui-datebox" data-options="
formatter:function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return (d<10?('0'+d):d) + '-' + (m<10?('0'+m):m) + '-' + y;
},
parser: function(s){
if (!s){return new Date();}
var ss = s.split('-');
var d = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var y = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
return new Date(y,m-1,d);
} else {
return new Date();
}
},
onShowPanel: function(){
var c = $(this).datebox('calendar');
c.calendar({
validator: function(date){
var now = new Date();
var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var d2 = new Date(now.getFullYear(), now.getMonth(), now.getDate()+10);
return d1<=date && date<=d2;
}
})
}
">
Logged
bakkers
Newbie
*
Posts: 21


View Profile Email
« Reply #2 on: October 08, 2015, 11:15:33 PM »

Yes that worked perfectly.

Thank you very much Smiley
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!