Angularjs form validation: Form Reset button not getting enabled and is not clearing the fields while those fields have invalid inputs

142 views
Skip to first unread message

sourav paul

unread,
Apr 2, 2014, 2:42:06 AM4/2/14
to ang...@googlegroups.com

Problem Statement:

Step 1: Open the plunkr URL:  http://plnkr.co/edit/ngdoc:example-example100@snapshot?p=preview

Step 2: Give input to "Name" filed. The "Reset" button is enable now. Its OK.

Step 3: Refresh the page. 

Step 4: Now leave "Name" field empty and type some invalid email(like: test) to "Email" field. Here is the problem I found, The Reset button is not enabled.

Step 5: Now enter some text in "Name" filed. Now the Reset button is enabled.

Step 6: Click on Reset button.

Step 7: Here is another problem. Its clearing the input text for "Name" but not for "Email".


I tried with version 1.2.15.
_________________________________________________________________

Solution I tried:
I made changes in angular.js file and it working fine now.

Here is my change:
function validate(ctrl, validatorName, validity, value){
  ctrl.$setValidity(validatorName, validity);
  return value;
}










Please let me know if there is any other way we can fix this.


Sander Elias

unread,
Apr 2, 2014, 3:32:47 AM4/2/14
to ang...@googlegroups.com

Hi Sourav,

You did not provide defaults in your code, this confuses me, and apparently also some parts in your code ;)
if you do this in your controller:

    $scope.master = {
       name:'',
       email:''
    };

Your sample will work as expected.

Regards
Sander

sourav paul

unread,
Apr 2, 2014, 5:53:41 AM4/2/14
to ang...@googlegroups.com
Thanks Sander for your reply.

Actually I got the Plunker link from docs.angularjs.org (http://docs.angularjs.org/guide/forms) .

I have updated the Plunker code by adding the defaults as you said and its enabling the Reset button now.
But if we check in console the "Email" is undefined (in $scope) until we provide valid input for email.

Also if we remove the text entered for email; can we disable the Reset button again?


Regards,
Sourav
Reply all
Reply to author
Forward
0 new messages