Manage optionnal fields

This commit is contained in:
William Bouzourène 2025-01-06 17:05:03 +01:00
parent 3e4cc96027
commit 360ed9acd4
7 changed files with 518 additions and 0 deletions

130
views/field_form.html Normal file
View file

@ -0,0 +1,130 @@
{% extends "layouts/main.html" %}
{% block main %}
<div class="container mt-4">
<div class="mb-4">
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item"><a href="/admin">Administration</a></li>
<li class="breadcrumb-item"><a href="/admin/fields">Champs supplémentaires</a></li>
{% if Field.ID %}
<li class="breadcrumb-item">
<a href="/admin/fields/{{ Field.ID }}">{{ Field.Name }}</a>
</li>
<li class="breadcrumb-item active">Modifier</li>
{% else %}
<li class="breadcrumb-item active">Ajouter</li>
{% endif %}
</ol>
</nav>
<hr>
</div>
{% if Errors %}
<div class="alert alert-danger">
<ul class="m-0">
{% for Error in Errors %}
<li>{{ Error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<form id="field" method="post">
<div class="mb-3">
<label for="name" class="form-label">
Nom du champ
</label>
<input
id="name"
class="form-control"
type="text"
name="name"
required
value="{{ Field.Name }}"
>
</div>
{% if !Field.ID %}
<div class="mb-3">
<label for="person_type" class="form-label">
Population
</label>
<select
name="person_type"
id="person_type"
class="form-control"
required
>
{% for Key, Value in PersonTypes %}
<option value="{{ Key }}">{{ Value }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="field_type" class="form-label">
Type de champ
</label>
<select
name="field_type"
id="field_type"
class="form-control"
required
>
{% for Key, Value in FieldTypes %}
<option value="{{ Key }}">{{ Value }}</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label for="list" class="form-label">
Liste
</label>
<select
name="list"
id="list"
class="form-control"
required
>
{% for List in Lists %}
<option value="{{ List.ID }}">
{{ List.Name }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="mt-4">
<button class="btn btn-primary" type="submit">
<i class="me-1 bi-floppy"></i>
Enregistrer
</button>
</div>
</form>
</div>
{% endblock %}
{% block javascript %}
<script>
$(document).ready(function() {
$("#field_type").on("change", function() {
var enable = false;
if ($(this).val() == "list") {
enable = true;
}
$("#list").prop("disabled", !enable);
$("#list").prop("required", enable);
});
$("#field_type").trigger("change");
});
</script>
{% endblock %}