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

Button type "reset" and form reset() method yield different results in inputs and date inputs #1071

Closed
dtopalov opened this issue Nov 10, 2017 · 2 comments

Comments

@dtopalov
Copy link
Contributor

dtopalov commented Nov 10, 2017

When a MaskedTextBox or a DateInput are used inside of a form, clicking a <button type="reset">reset</button> and using the ngForm's reset() method yield different results:

http://plnkr.co/edit/MmiKi6DGUE6yJCGYwqch?p=preview

Using the method works as expected, but using the button type "reset" or DOM form.reset() clears the internal HTML input's value.

It would be nice to provide a consistent experience regardless of whether the button or the form method is used.

@ggkrustev
Copy link
Contributor

ggkrustev commented Nov 10, 2017

The cleanest solution here will be to use input.defaultValue control property to utilize built-in DOM Form control support. Otherwise, we will need to tick inside the ControlValueAccessor.writeValue method to wait for the DOM Form to reset its internals first.

@ggkrustev
Copy link
Contributor

Our thorough investigation on the subject has shown that the browser indeed clears the input value after the Angular form has reset the components/directives. This seems incorrect in Angular form context and even unnecessary.

The best solution in this case is just to prevent the default form reset event and leave the Angular form to reset its content. Check this working example.

https://stackblitz.com/edit/angular-b3hyue

Will close the thread with this workaround, as we cannot do much on our side.

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

No branches or pull requests

2 participants