nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initiailise date from input

gbjbaanb opened this issue · comments

commented

I assume I'm missing something really obvious, but when clicking on the input field to pop the datepicker, the picker always sets itself to the current date, and not the date set in the input field. I can;t see any option to change this, it all seems to be centered around manually populating the picker with a new date object.

I use the bootstrap intergration, so there is no javascript to call when the input is clicked on by default, and I really don't want to have to add js event handlers to every element that might be a datepicker.

pickmeup_twitter_bootstrap() actually accepts options as an argument, so you can use everything specified in the readme, including date.

Also bootstrap integration doesn't mean you don't have full access to all features, it just adjusts styling according to current bootstrap theme in use.

commented

I want it to initialise with the date contained in the input element. not to initialise the picker with a date by reading it from the input element and setting it using the date option in javascript.

This is because I expect the date to be automatically initialised from the input field the picker is attached to (as this would be expected functionality). If I use the picker to select a date, and then re-open it, I would expect the date previously chosen to be in the picker, not the original.

The bootstrap integration is initialised by attaching the picker to a selector, so there is no easy way to initialise it with options based on the elements it gets attached to - eg if you call $('.pickerclass').pickmeup_twitter_bootstrap(), there's no way to say to it "this is the date that each element contains at startup".

Yeah, I agree it should have been initialized from the field it is attached to. Currently you can also use data-pmu- attributes to set initial date. For instance data-pmu-date="01-01-2001" should work.
I'll leave supporting input as a special case as potential improvement.

commented

I tried to update the js to handle it, but I couldn't quite figure out where it shoudl be put, and what the interaction between (IIRC) options.current, default_date and date variables were.

Just iterate over elements on the page and apply it to each element with unique settings or add attribute as I mentioned.

commented

why add these attributes, why not just read the value instead of duplicating the data?

That is the way it works in currently release version, it doesn't treat input element as a special case and often used in custom complex interfaces where everything is initialized with JavaScript anyway. PR with input[value] support is welcome though.