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