Skip to content

Commit 8273276

Browse files
committed
Provide users option to use * or optional: Issue #67
1 parent 48a0445 commit 8273276

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

README.rst

+17-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Create a virtualenv::
2121
At the command line::
2222

2323
$ pip install django-foundation-formtags
24-
24+
2525

2626
Usage
2727
-----
@@ -31,7 +31,7 @@ To start use django-foundation-forms in a project you must include in your setti
3131
INSTALLED_APPS = (
3232
'foundation_formtags',
3333
)
34-
34+
3535
In the template load foundation tags by::
3636

3737
{% load foundation_formtags %}
@@ -42,18 +42,28 @@ To use the django-form-foundation filter::
4242
{% csrf_token %}
4343
{{ form|as_foundation }}
4444
</form>
45-
45+
4646
To use the django-form-foundation field tags::
4747

4848
<form class="form" action="{{ url }}" method="POST">
4949
{% csrf_token %}
5050
{% render_field form.name %}
51-
51+
5252
{% render_field form.subject %}
53-
53+
5454
{% render_field form.message %}
5555
</form>
56-
56+
57+
Required versus optional fields
58+
-------------------------------
59+
60+
The normal behaviour is to mark required fields with `*`. If you want to mark only optional fields, you can add the following setting to your project settings file.
61+
62+
FOUNDATION_FORMTAGS_USE_OPTIONAL = True
63+
64+
To learn more about optional fields read this blog_.
65+
66+
.. _blog: https://www.formulate.com.au/blog/required-versus-optional-fields-new-standard
5767

5868
Contributing
5969
------------
@@ -63,4 +73,4 @@ little bit helps, and credit will always be given.
6373

6474

6575
* Free software: BSD license
66-
* Documentation: https://django-foundation-formtags.readthedocs.org.
76+
* Documentation: https://django-foundation-formtags.readthedocs.org.

docs/usage.rst

+16-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To start use django-foundation-forms in a project you must include in your setti
66
INSTALLED_APPS = (
77
'foundation_formtags',
88
)
9-
9+
1010
In the template load foundation tags by::
1111

1212
{% load foundation_formtags %}
@@ -17,14 +17,25 @@ To use the django-form-foundation filter::
1717
{% csrf_token %}
1818
{{ form|as_foundation }}
1919
</form>
20-
20+
2121
To use the django-form-foundation field tags::
2222

2323
<form class="form" action="{{ url }}" method="POST">
2424
{% csrf_token %}
2525
{% render_field form.name %}
26-
26+
2727
{% render_field form.subject %}
28-
28+
2929
{% render_field form.message %}
30-
</form>
30+
</form>
31+
32+
Required versus optional fields
33+
-------------------------------
34+
35+
The normal behaviour is to mark required fields with `*`. If you want to mark only optional fields, you can add the following setting to your project settings file.
36+
37+
FOUNDATION_FORMTAGS_USE_OPTIONAL = True
38+
39+
To learn more about optional fields read this blog_.
40+
41+
.. _blog: https://www.formulate.com.au/blog/required-versus-optional-fields-new-standard

foundation_formtags/templates/foundation_formtags/foundation_form_field.html

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
<small class="form-error is-visible chk">{{ error }}</small>
1414
{% endfor %}
1515
{% endif %}
16-
16+
1717
{% if field.label %}
1818
<label for="{{ field.auto_id }}" class={% if field.errors %}"is-invalid-label"{% endif %}>
1919
{{ field.label|safe }}
20-
{% if not field.field.required %}
21-
<span class="optional">(optional)</span>
22-
{% endif %}
20+
{% if not field.field.required and use_optional %}
21+
<span class="optional">(optional)</span>
22+
{% elif field.field.required and not use_optional %}
23+
<span class="required">*</span>
24+
{% endif %}
2325
</label>
2426
{% endif %}
2527

@@ -32,5 +34,5 @@
3234
<small>{{ field.help_text|safe }}</small>
3335
{% endif %}
3436
{% endif %}
35-
36-
{% endif %}
37+
38+
{% endif %}

foundation_formtags/templatetags/foundation_formtags.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
import types
44
from django import template
5+
from django.conf import settings
56
from django.template.loader import get_template
6-
from django.template import Context
77
from django.forms import CheckboxInput
88
register = template.Library()
99

1010

11+
FOUNDATION_FORMTAGS_USE_OPTIONAL = getattr(
12+
settings, 'FOUNDATION_FORMTAGS_USE_OPTIONAL', False
13+
)
14+
15+
1116
@register.filter
1217
def as_foundation(form):
1318
template = get_template("foundation_formtags/form.html")
14-
c = {"form": form}
19+
c = {"form": form, "use_optional": FOUNDATION_FORMTAGS_USE_OPTIONAL}
1520
return template.render(c)
1621

1722

0 commit comments

Comments
 (0)