EasyUI Forum

General Category => General Discussion => Topic started by: bakkers on October 08, 2015, 06:08:36 AM



Title: Databox validator
Post by: bakkers 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


Title: Re: Databox validator
Post by: stworthy 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;
}
})
}
">


Title: Re: Databox validator
Post by: bakkers on October 08, 2015, 11:15:33 PM
Yes that worked perfectly.

Thank you very much :)