How to show only before dates in JTSAGE date picke

2019-07-20 20:38发布

I use Jtsage date picker in my mobile application(jquery mobile and phonegap). I want to show only today and before today date(hide future dates ) so i refer this documentaion. In that documentation they mention afterToday,beforeToday,notToday,minDays,maxDays. I use beforeToday for my datebox but it seems not working.
My date picker calling is like:

 <input name="mydate" id="mydate" type="date" data-role="datebox" data-options='{"mode": "datebox", "useNewStyle":true,"afterToday":false,"beforeToday":true,"maxDays": 1}'/>

refer this Fiddle Demo

1条回答
【Aperson】
2楼-- · 2019-07-20 20:50

One way is to add an event to catch the 'set'. If date being set is in the future, popup a message and stopImmediatePropagation:

$('#mydate').on('datebox', function (event, payload) {
    if (payload.method === 'set') {
        var startdate = new Date();
        if (payload.date > startdate) {
            window.alert('You cannot select future dates!');
            e.stopImmediatePropagation();
        }
   }
});

Updated FIDDLE

查看更多
登录 后发表回答