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

StackOverflow https://stackoverflow.com/questions/20367998

  •  28-08-2022
  •  | 
  •  

Вопрос

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

Это было полезно?

Решение

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();
        }
   }
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top