up validate edit form
This commit is contained in:
parent
3ccfd732e7
commit
81c613e93c
4 changed files with 263 additions and 69 deletions
|
@ -5,6 +5,11 @@
|
|||
|
||||
{% block body %}
|
||||
<div class="container edit-land mt-4">
|
||||
|
||||
<pre>
|
||||
{{ dump(commerce_overpass) }}
|
||||
</pre>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title h2 mb-4">{{ 'display.welcome'|trans }} {{ commerce_overpass.tags_converted.name }}</h1>
|
||||
|
@ -175,7 +180,7 @@
|
|||
{% endblock %}
|
||||
{% block javascripts %}
|
||||
{{ parent() }}
|
||||
<script src={{asset('js/mapbox/mapbox-gl.js')}}></script>
|
||||
<script src="{{ asset('js/mapbox/mapbox-gl.js') }}"></script>
|
||||
<script>
|
||||
{% if commerce is not empty and mapbox_token is not empty and maptiler_token is not empty and commerce_overpass['@attributes'].lon is defined and commerce_overpass['@attributes'].lat is defined %}
|
||||
mapboxgl.accessToken = '{{ mapbox_token }}';
|
||||
|
@ -198,7 +203,68 @@ window.addEventListener('resize', () => {
|
|||
updateMapHeightForLargeScreens();
|
||||
});
|
||||
|
||||
check_validity();
|
||||
|
||||
function check_validity(e) {
|
||||
|
||||
list_inputs_good_to_fill = [
|
||||
'input[name="commerce_tag_value__contact:email"]',
|
||||
'input[name="commerce_tag_value__contact:phone"]',
|
||||
'input[name="commerce_tag_value__contact:website"]',
|
||||
'input[name="commerce_tag_value__contact:mastodon"]',
|
||||
'input[name="commerce_tag_value__address"]',
|
||||
'input[name="custom_opening_hours"]',
|
||||
'input[name="commerce_tag_value__contact:street"]',
|
||||
'input[name="commerce_tag_value__contact:housenumber"]',
|
||||
'input[name="custom__cuisine"]',
|
||||
]
|
||||
|
||||
list_inputs_good_to_fill.forEach(selector => {
|
||||
const input = document.querySelector(selector);
|
||||
if (input) {
|
||||
if (input.value.trim() !== '') {
|
||||
input.classList.add('good_filled');
|
||||
} else {
|
||||
input.classList.remove('good_filled');
|
||||
}
|
||||
}
|
||||
});
|
||||
let errors = [];
|
||||
document.querySelectorAll('.is-invalid').forEach(input => {
|
||||
input.classList.remove('is-invalid');
|
||||
});
|
||||
|
||||
const nameInput = document.querySelector('input[name="commerce_tag_value__name"]');
|
||||
if (!nameInput.value.trim()) {
|
||||
errors.push("Le nom de l'établissement est obligatoire");
|
||||
nameInput.classList.add('is-invalid');
|
||||
}
|
||||
|
||||
const emailInput = document.querySelector('input[name="commerce_tag_value__contact:email"]');
|
||||
if (emailInput && emailInput.value) {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(emailInput.value)) {
|
||||
errors.push("L'adresse email n'est pas valide");
|
||||
emailInput.classList.add('is-invalid');
|
||||
}
|
||||
}
|
||||
|
||||
const phoneInput = document.querySelector('input[name="commerce_tag_value__contact:phone"]');
|
||||
if (phoneInput && phoneInput.value) {
|
||||
const phoneRegex = /^(\+33|0)[1-9](\d{2}){4}$/;
|
||||
if (!phoneRegex.test(phoneInput.value.replace(/\s/g, ''))) {
|
||||
errors.push("Le numéro de téléphone n'est pas valide");
|
||||
phoneInput.classList.add('is-invalid');
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
e.preventDefault();
|
||||
document.querySelector('#validation_messages').innerHTML = errors.join('<br>');
|
||||
document.querySelector('#validation_messages').classList.add('is-invalid');
|
||||
}
|
||||
}
|
||||
|
||||
check_validity ? check_validity() : null;
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue