Skip to content

Commit

Permalink
Add template for form fields
Browse files Browse the repository at this point in the history
Is mostly universal, yet fields that require extra classes (like f.e. select2) need extra logic.
Meaning that with few tweaks this template has a potential to fix all add/edit templates in /seeddb.
Will finish and showcase this in a separate PR

fixup
  • Loading branch information
podliashanyk committed Sep 20, 2024
1 parent 008598a commit 927bb84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 18 additions & 0 deletions python/nav/web/templates/seeddb/_form_fields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% for field in form %}
<div id="div_id_{{ field.name }}"
class="ctrlHolder {% if field.errors %}error{% endif %}"
>
<label for="id_{{ field.name }}"
class="{% if field.field.required %}requiredField{% endif %}"
>
{{ field.label.title }}
{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{{ field }}
{% for error in field.field.errors %}
<small id="error_{{ forloop.counter }}_id_{{ field.name }}" class="error">
{{ error }}
</small>
{% endfor %}
</div>
{% endfor %}
17 changes: 9 additions & 8 deletions python/nav/web/templates/seeddb/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ <h4>{{ title }}
<form class="seeddb-edit" action="" method="post">
<fieldset>
<legend>Attributes</legend>
{% if form.no_crispy %}
{% block formfields %}
{% endblock %}
{% else %}
{% block crispyfields %}
{{ form|crispy }}
{% endblock %}
{% endif %}
{% if form.no_crispy %}
{% block formfields %}
{% include "seeddb/_form_fields.html" %}
{% endblock %}
{% else %}
{% block crispyfields %}
{{ form|crispy }}
{% endblock %}
{% endif %}
</fieldset>
<input type="submit" name="submit" value="Save {{ verbose_name }}" class="submit button small left" id="submit-id-submit">
</form>
Expand Down

0 comments on commit 927bb84

Please sign in to comment.