Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs reset form field with type of email

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!

like image 308
dzm Avatar asked Oct 21 '22 11:10

dzm


2 Answers

Just for the record, refer to the OP comments for explainations and see this plunker for a demo.

like image 79
jpmorin Avatar answered Oct 24 '22 10:10

jpmorin


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 ...

like image 25
Jscti Avatar answered Oct 24 '22 09:10

Jscti