Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Initiailise date from input #227

Open
gbjbaanb opened this issue Apr 26, 2020 · 8 comments
Open

Initiailise date from input #227

gbjbaanb opened this issue Apr 26, 2020 · 8 comments

Comments

@gbjbaanb
Copy link

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.

@nazar-pc
Copy link
Owner

nazar-pc commented May 2, 2020

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

@nazar-pc
Copy link
Owner

nazar-pc commented May 2, 2020

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.

@gbjbaanb
Copy link
Author

gbjbaanb commented May 2, 2020

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

@nazar-pc
Copy link
Owner

nazar-pc commented May 2, 2020

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.

@gbjbaanb
Copy link
Author

gbjbaanb commented May 2, 2020

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.

@nazar-pc
Copy link
Owner

nazar-pc commented May 3, 2020

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

@gbjbaanb
Copy link
Author

gbjbaanb commented May 3, 2020

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

@nazar-pc
Copy link
Owner

nazar-pc commented May 3, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants