Domanda

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

È stato utile?

Soluzione

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();
        }
   }
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top