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

[Date Picker] The date picker doesn't return the correct value when submitting the form with 'onChange' callback #417

Closed
ko2in opened this issue Jan 21, 2019 · 3 comments
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Milestone

Comments

@ko2in
Copy link
Member

ko2in commented Jan 21, 2019

Bug Report

I've a form with date picker and I setup to submit the form as soon as the date is picked and send the form data to the server. But, the form always sends the previous selected date.

Testcase

You can test in this fiddle (http://jsfiddle.net/m7wn3xus/3/). The date picker has onChange callback, which triggers the submit event of the form. You can see the serialized array of form data below. The form always send the previous value from the date picker.

Current Workaround Solution

I've to update the input field value with the selected date before triggering the submit event. You can test in this fiddle (http://jsfiddle.net/yka8fpsr/1/). The form will be sent the correct date to the server.

In my real world project, I'm implementing the search filters with several date fields and send to the server via Ajax request when the fields have changed the values.

The browser native onChange event has no effect on the date picker field. Looks like the date picker module unbind the default events. Try this fiddle (http://jsfiddle.net/54gsqa27/). The two text fields listen the change event, but the date picker field doesn't.

So, the only way to trigger the change event is using onChange callback from the date picker API, which causes the issue.

Version

2.7.1

@lubber-de lubber-de added type/bug Any issue which is a bug or PR which fixes a bug lang/javascript Anything involving JavaScript labels Jan 22, 2019
@ColinFrick
Copy link
Member

You are right, this differs to other modules where the onChange callback is called after the input is updated.

Splitting the onChange in beforeChange and onChange which is called after the value is set makes sense, but means a breaking change. This is similar to the checkbox module:
beforeChecked: Callback before a checkbox is checked. Can cancel change by returning false
onChecked: Callback after a checkbox is checked.

In the meantime you can delay submitting the form with setTimeout inside onChange: http://jsfiddle.net/fj3yxzh9/

@lubber-de lubber-de added this to the 2.8.x milestone Jan 22, 2019
@ko2in
Copy link
Member Author

ko2in commented Jan 22, 2019

@ColinFrick Thanks. That would do the trick at the moment 👍. Looking forward to the next release and the actual fix.

@prudho
Copy link
Contributor

prudho commented Sep 3, 2019

Fixed by #982.

@prudho prudho added the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Sep 3, 2019
@y0hami y0hami closed this as completed in 60989a5 Nov 14, 2019
@y0hami y0hami removed the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Projects
None yet
Development

No branches or pull requests

5 participants