Skip to content

Commit ef2fe0d

Browse files
committed
updated docs
1 parent ae87482 commit ef2fe0d

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

client/src/js/ng-django-angular-messages.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ if(angular.version.minor < 3 ) {
99

1010
angular
1111
.module('ng.django.angular.messages',[
12-
'ngMessages'
12+
'ng.django.forms'
1313
])
14-
1514
.directive('form', formDirectiveFactory())
1615
.directive('ngForm', formDirectiveFactory(true))
1716
.directive('djngError', djngError)

docs/angular-messages.rst

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Render Form field error lists in ngMessages format
1111
NgMessagesMixin
1212
===============
1313

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

1817
.. code-block:: python
1918
@@ -32,25 +31,24 @@ Then using ``{{ form.email.errors }}`` would output the following markup:
3231
<li ng-message="required" class="invalid">This field is required.</li>
3332
<li ng-message="email" class="invalid">Enter a valid email address.</li>
3433
<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>
3635
</li>
3736
</ul>
3837

3938

4039
Handling Ajax form errors
4140
.........................
4241

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

4746
.. code-block:: html
4847

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

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

5553
.. code-block:: javascript
5654
@@ -69,22 +67,24 @@ the rejected validator and display the error message.
6967
});
7068
7169
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``
7371
and display the message is necessary due to the following bug/issue_.
7472

7573
.. _bug/issue: https://github.com/angular/angular.js/issues/8089
7674

7775
.. code-block:: html
7876

7977
<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>
8179
</li>
8280

8381

8482
Use with other django-angular form mixins
8583
...........................................
8684

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+
8888
Valid examples:
8989

9090
.. code-block:: python
@@ -105,7 +105,17 @@ Or
105105
class MyNgMessagesForm(NgMessagesMixin, NgModelFormMixin, NgFormValidationMixin, NgForm):
106106
# custom form logic
107107
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
109119

110120
.. code-block:: python
111121

examples/server/forms/ng_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from . import subscribe_form
88

99

10-
class SubscribeForm(NgMessagesMixin, NgFormValidationMixin, NgModelFormMixin, subscribe_form.SubscribeForm):
10+
class SubscribeForm(NgMessagesMixin, NgModelFormMixin, NgFormValidationMixin, subscribe_form.SubscribeForm):
1111
scope_prefix = 'subscribe_data'
1212
form_name = 'my_form'
1313

examples/server/templates/ng-messages.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<script src="{{ STATIC_URL }}js/ng-django-angular-messages.js" type="text/javascript"></script>
4545
{% endblock scripts %}
4646

47-
{% block ng_module_dependencies %}['ng.django.forms', 'ng.django.angular.messages']{% endblock %}
47+
{% block ng_module_dependencies %}['ng.django.forms', 'ng.django.angular.messages', 'ngMessages']{% endblock %}
4848

4949
{% block demo_scripts %}
5050
{{ block.super }}

0 commit comments

Comments
 (0)