question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting Input Value With Alt Input Value

See original GitHub issue

Currently, using your library, I have a working calendar that has an input value and an alt input value. One thing that was asked of me was to have the ability to be able to manually edit the calendar and when you click away from the input box, the calendar will automatically update with the new value.

I am using your example here: https://jsfiddle.net/chmln/qf2b5yLa/2/ to try and get it to work however it does not. I assume it is due to the dates being the different formats and therefore it cannot set one to the other. Is there a built-in way to handle this?

Trying to extract the date with something like this doesn’t work either as it believes that the day and months are the opposite way round: myDate.getFullYear() + "-" + (myDate.getMonth()+1) + "-" + myDate.getDate();

Example code:

datePickerLoad : function(){
    	var optional_config = {
    		dateFormat: "Y-m-d",
    		altInput: true,
    		altFormat: "d/m/Y",
    		allowInput: true,
    		minDate: "1900-01",
    		onChange: function(selDates, dateStr) {
    		  	this._selDateStr = dateStr;
    		},
		onClose: function(selDates, dateStr, instance){
			if (this.config.allowInput && this._input.value && this._input.value !== this._selDateStr) {
			    this.setDate(this.altInput.value, false);
			}
    		}
    	}
    	
    	$(".date-picker").flatpickr(optional_config);
},
  • flatpickr version used: v2.5.7
  • Browser name and version: Chrome: 57.0.2987.110 (although FireFox seems to have the same behavior)
  • OS and version: Ubuntu 16.04

EDIT: I ended up using moment.js to get it working (although matching up the differing date formats was fiddly) but it doesn’t look as nice as letting flatpickr handle it all probably would have which is a shame. So I’ll likely close this issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
chmlncommented, Apr 24, 2017

Hey @huseyinham

You got very close to making it work. setDate() takes a third param where you specify the date format of the string you’re passing in.

So all you had to do was

setDate(this.altInput.value, false, this.config.altFormat);

You should also use something like Cleave to enforce the typed format. https://jsfiddle.net/chmln/2r3j0rgs/4/

0reactions
devinfdcommented, Jan 9, 2018

I’m facing the same issue that @vlledo mentioned above. Listening for the onChange event to clear the date does not work because onChange does not fire if allowInput: true. Is there are reason that self.clear(); is not called when allowInput: true? Perhaps it should if self._input.value is empty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Change Alt Value from another Input Field's value
I have two input fields within a form and would like that the value of the first input field is added to the...
Read more >
HTML input alt Attribute - W3Schools
The alt attribute provides an alternate text for the user, if he/she for some reason cannot view the image (because of slow connection,...
Read more >
HTML | <input> alt Attribute - GeeksforGeeks
Attribute Values: It contains single value text which is used to specify the alternative text for input if the image is not displaying....
Read more >
<input>: The Input (Form Input) element - HTML
How an <input> works varies considerably depending on the value of its type ... The alt attribute displays if the image src is...
Read more >
Input values and units | Webflow University
Once you've got your cursor in a numeric input field, you can hold Option (on Mac) or Alt (on Windows) then click and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found