How to programatically set a date in jquery mobile Datebox plugin 1.1.0

青春壹個敷衍的年華 提交于 2019-12-10 11:03:48

问题


I want to programmatically set date for the input with datebox control, For this i know i can use something like this

$(element).trigger('datebox', {'method':'set', 'value':'dateString'});

but this doesn't seem to update the control(i.e when i open the calendar, it is set to current date and not equal to the value in the input field)

EDIT: based on JTsage's pointers i overwrote the default dateformat to mm/dd/yyyy, using sth like this.

jQuery.extend(jQuery.mobile.datebox.prototype.options.lang, {
    'en': {
        dateFormat: '%m/%d/%Y'

    }
});
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
    useLang: 'en'
});

Then i tried setting the date using sth like this

$(element).trigger('datebox', {'method':'set', value:'07/02/2012'});

but this date is not appearing when i navigate to the page..Interestingly when i tried updating the date from firebug console(being on that page) it updated the field as well as datebox control.

I have no idea why this is happening..Need help, please respond JT


回答1:


So finally i fixed the issue, by doing this

jQuery.extend(jQuery.mobile.datebox.prototype.options, {
    'overrideDateFormat': '%m-%d-%Y',
    'overrideHeaderFormat': '%m-%d-%Y'
});

setting the value of the input field explicitly

$(element).val('06-21-2012');

and then refreshing the datebox

$(element).trigger('datebox', {'method':'set', 'value':'06-21-2012'});



回答2:


I found th solution, try this

 $(element).trigger('datebox', { 'method': 'doset' });


来源:https://stackoverflow.com/questions/11273029/how-to-programatically-set-a-date-in-jquery-mobile-datebox-plugin-1-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!