jtsage / jtsage-datebox

A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
http://datebox.jtsage.dev/
Other
474 stars 166 forks source link

Displaying today's date in the input box at start-up #273

Closed ghost closed 11 years ago

ghost commented 11 years ago

We have a date field on our form which would normally be populated with today's date but which the user can change (using calbox). We want to copy the behaviour of our non-mobile site and display a suitably formatted date, without the user having to select today from the popup.

I could not find an existing configuration option to do this, so I would propose the following addition to the "_create" event -

// existing code from line 764 (approx) w.initDate = new w._date(); w.theDate = (o.defaultValue) ? w._makeDate(o.defaultValue) : new w._date(); w.initDone = false;

// new code .... if ( (typeof (o.showInitialValue) !== "undefined") && (o.showInitialValue === true) { w.d.input.val(w._formatter(w.__fmt(), w.theDate)); }

The control would be configured thus -

.... data-options='{"mode":"calbox", "showInitialValue":true .....

Would this be appropriate?

Chris

jtsage commented 11 years ago

Yes, with one exception - defined "showInitialValue" in the options section up at the top (as false), then you can drop the typeof check, since it can be assumed to be false unless the end user overrides it. (Your method is of course not wrong, this just keeps with the style of the rest of the piece)

~j

ghost commented 11 years ago

J, Thanks, I should have thought of that, I've looked at this code long enough, trying to confirm if such a feature was available. Sorry about the partial solution :)

Thanks for a great plugin. Chris