-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
didReceiveAttrs does not trigger onChange #119
didReceiveAttrs does not trigger onChange #119
Conversation
9b5ed93
to
14b7638
Compare
Thanks for the PR @staskij! Looking at the flatpickr docs, they seem to indicate that it won't trigger onChange unless you pass If it doesn't work as advertised, we might want to have them fix it there. My only concern with this is making sure all the locales and formats and everything work the same with this change. Does everything look the same generally or did you test that out? |
flatpickr#setDate uses if (triggerChange !== false)
triggerEvent("Change"); to check if onChange should be triggered, so I'm afraid there is a difference in formatting if not using altFormat: |
@staskij what if we switched Perhaps we should think up all the possible cases of setting the value and ensure we have tests for each of them and they all behave as they should? |
I'm wrong about dateFormat being ignored in displaying. Using setDate() without false causes the "you modified twice" error before glimmer rerenders, so the date is not updated. My understanding of flatpickr formats is that:
So, we should check that:
I'm not sure if we should check anything more about formats, this is mostly a wrapper around flatpickr, most of the data manipulation gets implemented by the user in onChange/onClose/other events. |
Sorry if I'm being overly verbose in this PR, but i'm trying to understand what we should do. onChange receives the three arguments from the flatpickr onChange event API, so if we destructure the first argument in a onChange action (like in the last test i added) we have no problem, but if we use
|
71300a4
to
c62e3eb
Compare
@staskij it should be expected to be an array at all times now, I believe. When flatpickr switched to supporting selecting multiple dates on one calendar, they defaulted to arrays everywhere. Definitely possible we have some tweaking to do on the ember-flatpickr side to support this. I agree that it should be consistent. |
@staskij nice work and investigating! Since // Assume the value is a computed property with set:
value: Ember.computed({
set(key, value) {
const [date] = value;
// convert that date object to a specific format.
return moment(date).format('YYYY-MM-DD');
}
}); |
@GCheung55 sounds logical to me, at least at first glance. Could you and @staskij work together on creating a solution that you both agree on and then I'll get it merged in? I won't have much time to look into this myself for a couple weeks, unfortunately, but if you both agree it's good to go, and formatting and everything still works, I'll happily merge 😃 |
@staskij @GCheung55 do you think you guys would have the time to collaborate on this and get this PR to a mutually accepted solution that handles all the things? |
Well, I believe this PR should handle the problem of not updating the value twice each time a new date gets selected, and I believe the tests I've added show that setting setDate(*, false) solves the problem and leaves As per "what should we expect as input and what should we return as output", it should be discussed more, but without the setDate(*, false) this component cannot be used anywhere atm, as the basic use-case is broken. So I'm open to new discussions related to input and output formats in another pr/issue, but I'm thinking this pr should be small, fast and fix only the warning ember throws. I'm only adding to this pr a little bit of documentation on how to handle input and output on this very moment. Let me know if solving this issue alone and discussing |
@staskij can you check what version of |
The problem does not occur if in production mode, only in development mode:
EDIT: oh sorry, you meant flatpickr, yeah it's newer than 2.3.2, just can't find which version is twiddle pulling |
@staskij look at http://shipshapecode.github.io/ember-flatpickr/ If you look in the console, notice nothing is printed from an onChange until you change the value by interacting with the flatpickr. |
@staskij looks like the behavior did indeed change in flatpickr. https://github.com/chmln/flatpickr/blob/v2.3.2/src/flatpickr.js#L1259 Thanks to @GCheung55 for finding that! So we may want to just discuss getting this fixed in flatpickr itself. You could lock your flatpickr to 2.3.2 for now, for a quick fix. I just don't have the time to do a lot of digging into this right now. |
@staskij @GCheung55 seems like @chmln is going to revert the behavior flatpickr/flatpickr#666 (comment), thus potentially fixing this issue without need for this PR. Might want to at least keep some of the tests introduced here though. Will follow up when the change has been made on the flatpickr side. |
@staskij seems like the behavior has been reverted now. Can you please remove your changes here, but keep the relevant tests? Happy to merge the tests in to ensure this doesn't happen again 😄 |
d31f654
to
9fb68c1
Compare
I rebased the pr, leaving only the 4 tests and the change in the README. This fails on travis as travis pulls flatpickr without the reverted behaviour, but as a new flatpickr version gets released they'll succeed. Shouldn't we also upgrade package.json to use the to-be released flatpickr? Any version of flatpickr from 2.4 to 2.4.4 have the "setDate triggers onChange by default" behaviour, and so they cause the error. |
@staskij yeah, we will update the version when they release it |
did they do it? flatpickr/flatpickr@a033486 |
@NullVoxPopuli yeah, they changed it back, but have not released a new version yet |
Updated flatpickr. Going to merge this, and adjust to add any tweaks necessary for the new flatpickr, then will get a new version of ember-flatpickr out ASAP. |
Fixes #115, #114.
Added a test too.
This implies that an external change to value shouldn't trigger onChange, which seems fair to me.