How to prevent Jquery Mobile datebox from closing if user selects invalid date

209 views Asked by At

I am using jQuery Mobile datebox plugin to select the date range. If user selects the start date greater than end date, then i want to show the alert and keep the datebox open.

  $('#sDate').on('datebox', function (event, payload) {
                if (payload.method === 'set') {
                    if (payload.date > eDate) {
                        window.alert('Select start date less than end date.');
            //Keep datebox open
                    }
                    else {
                     //Proceed with data filtering
                    }
                }
            });

But Datebox is getting closed. Is there any option of datebox which allows to prevent datebox from closing (probably without any hack or work around).

1

There are 1 answers

2
ezanker On BEST ANSWER

Here is a DEMO FIDDLE

Just add e.stopImmediatePropagation(); after the alert:

$('#sDate').on('datebox', function (event, payload) {
    if (payload.method === 'set') {
        if (payload.date > eDate) {
            window.alert('Select start date less than end date.');
            e.stopImmediatePropagation();
        }
   }
});