2

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

2
  • This is the correct method - but it will only work if 'dateString' is in the same format that DateBox is outputting. Commented Jun 30, 2012 at 13:18
  • Thanks for replying, i think that's the only thing i am missing. Will try that and update the same, again thanks for such a good plugin. Commented Jul 1, 2012 at 15:14

2 Answers 2

7

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'});
Sign up to request clarification or add additional context in comments.

1 Comment

While this is fine, it would be nicer to be able to set the date by an actual Date object. There is a method for this: $(element).datebox('setTheDate', new Date()); Unfortunately, this does not update the widget.
0

I found th solution, try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.