@@ -11,9 +11,8 @@ Render Form field error lists in ngMessages format
11
11
NgMessagesMixin
12
12
===============
13
13
14
- The ``NgMessagesMixin `` mixin can be used in conjunction with other django-angular form mixins (``NgFormValidationMixin ``
15
- and ``NgModelFormMixin ``) or on its own, to facilitate the rendering of form field error lists, in the
16
- correct format for the ngMessages directive.
14
+ The ``NgMessagesMixin `` mixin is used in conjunction with the ``NgFormValidationMixin `` to facilitate
15
+ the rendering of form field error lists, in the correct format for the ngMessages directive.
17
16
18
17
.. code-block :: python
19
18
@@ -32,25 +31,24 @@ Then using ``{{ form.email.errors }}`` would output the following markup:
32
31
<li ng-message =" required" class =" invalid" >This field is required.</li >
33
32
<li ng-message =" email" class =" invalid" >Enter a valid email address.</li >
34
33
<li ng-message =" rejected" class =" invalid" >
35
- <span ng-bind =" my_form.email.$message.rejected " ></span >
34
+ <span ng-bind =" my_form.email.$message" ></span >
36
35
</li >
37
36
</ul >
38
37
39
38
40
39
Handling Ajax form errors
41
40
.........................
42
41
43
- The ``NgMessagesMixin `` also adds the ``djng-validate- rejected `` directive attribute to each form ``input ``.
44
- This directive handles the display of server side errors, by adding a ``rejected `` validator to the ``input ``'s
45
- ``ngModel.$validators `` array .
42
+ The ``NgMessagesMixin `` adds the ``djng-rejected `` directive attribute to each form ``input ``. This directive
43
+ handles the display and remvoval of server side errors, by adding a ``rejected `` validator to the ``input ``'s
44
+ ``ngModel.$validators `` pipeline .
46
45
47
46
.. code-block :: html
48
47
49
- <input id =" id_email" name =" email" ng-model =" email" type =" email" required = " required " djng-validate -rejected >
48
+ <input id =" id_email" name =" email" ng-model =" email" type =" email" required djng-rejected >
50
49
51
- The ``djngAngularMessagesForm.setErrors `` method is then used to parse the errors from the server response, apply them
52
- to the relevant fields ``field.$message.rejected `` property and call the fields ``$validate `` method to trigger
53
- the rejected validator and display the error message.
50
+ The ``djngAngularMessagesForm.setErrors `` method is used to parse the errors from the server response and apply
51
+ them to the relevant fields.
54
52
55
53
.. code-block :: javascript
56
54
@@ -69,22 +67,24 @@ the rejected validator and display the error message.
69
67
});
70
68
71
69
The markup below is a snippet of the ``{{ form.email.errors }} `` shown earlier. It shows the specific part that deals
72
- with the display of the rejected error message. The ``<span> `` to bind to the value of ``my_form.email.$message.rejected ``
70
+ with the display of the rejected error message. The ``<span> `` to bind to the value of ``my_form.email.$message ``
73
71
and display the message is necessary due to the following bug/issue _.
74
72
75
73
.. _bug/issue : https://github.com/angular/angular.js/issues/8089
76
74
77
75
.. code-block :: html
78
76
79
77
<li ng-message =" rejected" class =" invalid" >
80
- <span ng-bind =" my_form.email.$message.rejected " > /* rejected error message will be displayed here */ </span >
78
+ <span ng-bind =" my_form.email.$message" > /* rejected error message will be displayed here */ </span >
81
79
</li >
82
80
83
81
84
82
Use with other django-angular form mixins
85
83
...........................................
86
84
87
- When using the ``NgMessagesMixin ``, the form class must always inherit from ``NgMessagesMixin `` first.
85
+ The ``NgMessagesMixin `` must always be used in conjunction with the ``NgFormValidationMixin `` and it should also
86
+ be inherited after all other django-angular form mixins.
87
+
88
88
Valid examples:
89
89
90
90
.. code-block :: python
105
105
class MyNgMessagesForm (NgMessagesMixin , NgModelFormMixin , NgFormValidationMixin , NgForm ):
106
106
# custom form logic
107
107
108
- But not
108
+ Invalid examples:
109
+
110
+ .. code-block :: python
111
+
112
+ from django import forms
113
+ from djangular.forms import NgForm, NgModelFormMixin, NgMessagesMixin
114
+
115
+ class MyNgMessagesForm (NgMessagesMixin , NgModelFormMixin , NgForm ):
116
+ # custom form logic
117
+
118
+ Or
109
119
110
120
.. code-block :: python
111
121
0 commit comments