Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-reset #2726

Closed
honzajde opened this issue May 21, 2013 · 6 comments
Closed

ng-reset #2726

honzajde opened this issue May 21, 2013 · 6 comments

Comments

@honzajde
Copy link

If there is ng-submit directive, is there any specific reason that there is no ng-reset directive?

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@JasonCust
Copy link

Would this approach work? http://jsfiddle.net/GlobalDomestic/GjPwK/5

Of course this is a bit of a hack since I can't access the ng-form directive controls array directly (without an actual PR).

One issue is storing initial model values as the digest loop needs time to stabilize the model values. Using $timeout for this seems clumsy to me.

Another thought was if someone applied model values after the form was created. Should that be supported as the default value? If so, how should that be conveyed?

Thoughts?

@honzajde
Copy link
Author

Nice!

Capturing 'initial state' - Yes, calling $timeout with (implicit) 0 delay might be an issue - if someobody:

  1. uses $timeout to trigger additional changes on the model with the same delay (to get the initial state) - order is not guaranteed
  2. modifies ui elements directly which causes another digest cycle which results to final initial state..

Ad 2) is a bad practice..
Ad 1) is a valid approach (slightly edgy - see discussions around $debounce service #2690 ), in this case we would need to reset the reset explicitly:) - by adding mehod 'initReset()' on form object ?

@honzajde
Copy link
Author

reacting to $$postDigest event is another way of capturing the 'initial state'

@JasonCust
Copy link

@btford Any thoughts on this? Just wondering if it's worth any continued effort.

@radekn
Copy link

radekn commented Jul 15, 2014

I like the idea of forms accepting ng-reset attribute analogous to ng-submit, and I think this issue should be reopened.

Right now, reset buttons clear the fields while leaving the model intact (rather not desired behavior), and if I want to prevent this (and add my own logic for resetting form), I need to use $event.preventDefault in button's ng-click. I think it would be much cleaner if I could do it in form's ng-reset instead.

@JasonCust Your ng-reset is not very consistent with ng-submit. What if I wanted to supply my own logic for resetting the form? I'd much more like ng-reset to be a place for doing it myself, rather than a switch for some automagic functionality.

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

No branches or pull requests

4 participants