Question

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).

Was it helpful?

Solution

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();
        }
   }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top