In AngularJs it seems that when you try to 'reset' a form, by setting all of the models to an empty object, if an input is type="email"
this doesn't get cleared. Changing it to type="text"
works however, but then you lose the red border on validation.
Is there anyway to reset or clear an email type input?
Thanks!
Just for the record, refer to the OP comments for explainations and see this plunker for a demo.
In my case , when using a validation form button binded to the scope with ng-disabled
directive, I had to use double reset logic :
<form>
<input type="email" ng-model="formdata.email" />
<button class="btn btn-warning cancel" type="reset" ng-click="formdata = {}">Clear</button>
<button type="submit" ng-disabled="form.$invalid" />
</form>
type="reset"
: in order to clear the field even when an invalid email is currently filling the field (without this attribute, an invalid email isn't removed by the ng-click
)
ng-click="formdata = {}"
: reinitialize all scope bindings. Without that, when reseting form, the ng-disabled won't update and the validate button will still be enabled after reset ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With