Skip to content
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

Dom value not updated when using typeable #79

Closed
julsbreakdown opened this issue Jan 28, 2021 · 10 comments · Fixed by #89
Closed

Dom value not updated when using typeable #79

julsbreakdown opened this issue Jan 28, 2021 · 10 comments · Fixed by #89
Labels
bug Something isn't working

Comments

@julsbreakdown
Copy link

julsbreakdown commented Jan 28, 2021

Hello,
I am having issues when reseting a date.
When selecting a date using the datepicker every thing works as expected.
However when i type the date inside the input (using typeable=true), the dom value is not updated.
The prop value however is updated.

<datepicker
          :typeable="true"
          :value="minDate"
          :language="fr"
          format="dd/MM/yyyy"
          v-on:selected="$emit('min-date', $event)"
          v-on:input="$emit('min-date', $event)"
          input-class="datepicker-input"
        >
</datepicker>
    props: {
      name: String,
      minDate: Date,
      maxDate: Date,
    },
   watch: {
      minDate: function (newVal, oldVal) { // watch it
        console.log('Prop changed: ', newVal, ' | was: ', oldVal)
      }
    },

When changing the value with the datepicker, both newVal & oldVal are correct, and the Dom IS UPDATED
But when changing the value using the input, both newVal & oldVal are correct, and the Dom IS NOT UPDATED

Thanks in advance for any feeback

@MrWook
Copy link
Collaborator

MrWook commented Jan 28, 2021

Hey, i will look into it next week.

In the meantime did you try to use v-model?
v-model should be always up to date and you could watch the value from it

@julsbreakdown
Copy link
Author

I did try both. No change =(
Thanks

@MrWook
Copy link
Collaborator

MrWook commented Feb 1, 2021

Hey, i tested your case with v-model and everything seems to be correct.

If i select a date or type it, the events and the model will change to the new date even if i get the date with a js selector like document.querySelector(".myInput").value

Maybe the events are confusing because a blur event on the input field will trigger the other events again. In this trigger the new and old value are the same.

For example if you have the date 2020-05-05 and you change it either by typing or selecting to 2021-06-06 the events will trigger on the selection or typing and have the values like this:
newVal: 2021-06-06
oldVal: 2020-05-05

If you click on something else so that the blur event on the input field is triggered the other events are triggered as well and results in:
newVal: 2021-06-06
oldVal: 2021-06-06

Let me know if this is what bugs you.

@julsbreakdown
Copy link
Author

julsbreakdown commented Feb 4, 2021

hello @MrWook
Thanks for the feedback, my problem remains. I will try to explain it differently.
Using the logs:
image

1st log is when selecting 04/05 using the datepicker widget
2nd log is reseting the input Value => initial value is displayed correctly in the input 01/05
3rd log is when changing the date inside the input (typeable)
4th log is when the focus leaves the input
5th log is reseting the input Value => initial value is not displayed, it is still 04/05 in the input

Dates are reset in log 2 & 5 and the values logged are identical. But not the displayed value inside the input text
Thanks

@MrWook
Copy link
Collaborator

MrWook commented Feb 8, 2021

I'm still confused. If i add the clear-button prop to reset the date it's still working even if i add a new button to clear the model everything is updated.
Do you mind creating a reproduction repo or some kind of codesandbox online so i can check it out?

@julsbreakdown
Copy link
Author

julsbreakdown commented Feb 9, 2021

Hello @MrWook
Here is a codepen
https://codepen.io/jujulelama/pen/rNWLENV

Change the value directly in the input to 2025 for example.
Then click on reset => date does not change
Change the value using the datepicker to 2025
Then click on reset => date is updated

@MrWook
Copy link
Collaborator

MrWook commented Feb 9, 2021

For me everything works fine :/
Which browser are you using?

@julsbreakdown
Copy link
Author

I press enter after typing the input

@MrWook
Copy link
Collaborator

MrWook commented Feb 9, 2021

Ah yes i see thank you for the report, i will try and fix it

@MrWook MrWook added the bug Something isn't working label Feb 9, 2021
mst101 added a commit to mst101/vue-datepicker that referenced this issue Feb 16, 2021
@julsbreakdown
Copy link
Author

@MrWook Thanks for the fixe, when will you do the next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants