From f46ab8ee3d2bb6df91f436a76370db229abfbe30 Mon Sep 17 00:00:00 2001 From: Clay Anderson Date: Fri, 14 Nov 2014 15:22:56 -0700 Subject: [PATCH 1/2] Enhanced form examples to utilize $touched The "Binding to form and control state" example now more closely reflects how users will accomplish form validation in 1.3. For example, users are now informed of validation requirements upon clicking Save. --- docs/content/guide/forms.ngdoc | 75 +++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/docs/content/guide/forms.ngdoc b/docs/content/guide/forms.ngdoc index 370ffbe3f5c7..cb32b2ae34af 100644 --- a/docs/content/guide/forms.ngdoc +++ b/docs/content/guide/forms.ngdoc @@ -27,8 +27,8 @@ for other directives to augment its behavior. E-mail:
Gender: male female
- - + +
form = {{user | json}}
master = {{master | json}}
@@ -77,29 +77,28 @@ To allow styling of form as well as controls, `ngModel` adds these CSS classes: The following example uses the CSS to display validity of each form control. In the example both `user.name` and `user.email` are required, but are rendered -with red background only when they are dirty. This ensures that the user is not distracted +with red background only when they are touched. This ensures that the user is not distracted with an error until after interacting with the control, and failing to satisfy its validity.
- Name: -
+ Name:
E-mail:
Gender: male female
- - + +
@@ -140,34 +139,42 @@ the view using the standard binding primitives. This allows us to extend the above example with these features: -- RESET button is enabled only if form has some changes -- SAVE button is enabled only if form has some changes and is valid -- custom error messages for `user.email` and `user.agree` +- Custom error message displayed upon interacting (touching) a field or submitting the form
Name: -
+ +
+
+
Tell us your name.
+
+ E-mail: -
-
Invalid: + +
+
Tell us your email. This is not a valid email.
- Gender: male - female
- - - I agree:
-
Please agree and sign.
- - - + Gender: + male + female +
+ + + I agree: + +
+
+
Please agree and sign.
+
+ + +
@@ -176,19 +183,19 @@ This allows us to extend the above example with these features: angular.module('formExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.master = {}; - + $scope.update = function(user) { $scope.master = angular.copy(user); }; - - $scope.reset = function() { + + $scope.reset = function(form) { + if (form) { + form.$setPristine(); + form.$setUntouched(); + } $scope.user = angular.copy($scope.master); }; - - $scope.isUnchanged = function(user) { - return angular.equals(user, $scope.master); - }; - + $scope.reset(); }]); From 38ee6c24afcef8202d85d23514c89790f10c4cfc Mon Sep 17 00:00:00 2001 From: Clay Anderson Date: Tue, 18 Nov 2014 15:04:22 -0700 Subject: [PATCH 2/2] Clarified wording --- docs/content/guide/forms.ngdoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/content/guide/forms.ngdoc b/docs/content/guide/forms.ngdoc index cb32b2ae34af..8be57fb8f271 100644 --- a/docs/content/guide/forms.ngdoc +++ b/docs/content/guide/forms.ngdoc @@ -139,7 +139,9 @@ the view using the standard binding primitives. This allows us to extend the above example with these features: -- Custom error message displayed upon interacting (touching) a field or submitting the form +- Custom error message displayed after interacting with a control (i.e. `$touched`) +- Custom error message displayed upon submitting the form even if user didn't interact with a control (i.e. `$submitted`) +