-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tree_types): Validation Tree Types (#150)
This pull request includes several changes to improve the admin layout, tree type model, and tree type views. The most important changes include moving the JavaScript import in the admin layout, removing the `photo_id` field from the `TreeType` model, updating the tree type creation and edit forms, and adding client-side validation for the tree type form. Admin layout updates: * Moved the `app.js` script import to the end of the body in `AdminLayout.php` to improve page load performance. [[1]](diffhunk://#diff-e43b091c2e5f4ff0f2b90b03cfee557777f5d3df706873e74b366fa34d9aa051L10) [[2]](diffhunk://#diff-e43b091c2e5f4ff0f2b90b03cfee557777f5d3df706873e74b366fa34d9aa051R130) Tree type model updates: * Removed the `photo_id` field and the associated `photo` method from the `TreeType` model. [[1]](diffhunk://#diff-9b6e2b512620cbcf6691b6ebed684af80c6d3071e2078483f32bff09693632d9L13-L14) [[2]](diffhunk://#diff-9b6e2b512620cbcf6691b6ebed684af80c6d3071e2078483f32bff09693632d9L27-L36) Tree type view updates: * Updated the back button URL in the tree type creation and edit views to point to the correct admin route. [[1]](diffhunk://#diff-44d3d8172b626b0986e1ec03c382c4a1ea15ff0c7ae3df656290f9e83bb2126eL2-R2) [[2]](diffhunk://#diff-78a2b54262dc0a49ba0f676ccd46806c3483d7f6a76d921b3edc39e50f240536L2-R2) * Added an `id` attribute to the tree type creation and edit forms and included an error message container for validation feedback. [[1]](diffhunk://#diff-44d3d8172b626b0986e1ec03c382c4a1ea15ff0c7ae3df656290f9e83bb2126eL14-R17) [[2]](diffhunk://#diff-78a2b54262dc0a49ba0f676ccd46806c3483d7f6a76d921b3edc39e50f240536L14-R17) Client-side validation: * Added a new JavaScript function `validateFormTreeType` in `app.js` to perform client-side validation for the tree type form fields and display error messages if validation fails.
- Loading branch information
Showing
6 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,4 @@ class="text-red-500 hover:text-red-700" title="Delete"> | |
<?php } ?> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
function validateFormTreeType(event) { | ||
// Contenidor per a tots els errors | ||
const errorMessagesDiv = document.getElementById("errorMessages"); | ||
|
||
// Netejar errors anteriors | ||
errorMessagesDiv.innerHTML = ""; // Eliminar contingut d'errors | ||
errorMessagesDiv.classList.add("hidden"); // Amagar inicialment | ||
|
||
let hasError = false; // Controlar si hi ha errors | ||
let errorMessage = ""; // Acumular missatges d'error | ||
|
||
// Expressió regular per validar noms (només lletres i espais) | ||
const namePattern = /^[a-zA-Z\s]+$/; | ||
|
||
// Validació de cada camp | ||
const family = document.getElementById("family").value.trim(); | ||
const genus = document.getElementById("genus").value.trim(); | ||
const species = document.getElementById("species").value.trim(); | ||
|
||
if (!family) { | ||
errorMessage += "<p>- La família és obligatòria.</p>"; | ||
hasError = true; | ||
} else if (!namePattern.test(family)) { | ||
errorMessage += | ||
"<p>- La família només pot contenir lletres i espais.</p>"; | ||
hasError = true; | ||
} | ||
|
||
if (!genus) { | ||
errorMessage += "<p>- El gènere és obligatori.</p>"; | ||
hasError = true; | ||
} else if (!namePattern.test(genus)) { | ||
errorMessage += | ||
"<p>- El gènere només pot contenir lletres i espais.</p>"; | ||
hasError = true; | ||
} | ||
|
||
if (!species) { | ||
errorMessage += "<p>- L'espècie és obligatòria.</p>"; | ||
hasError = true; | ||
} else if (!namePattern.test(species)) { | ||
errorMessage += | ||
"<p>- L'espècie només pot contenir lletres i espais.</p>"; | ||
hasError = true; | ||
} | ||
|
||
// Si hi ha errors, mostrar el contenidor i prevenir l'enviament del formulari | ||
if (hasError) { | ||
errorMessagesDiv.innerHTML = errorMessage; // Inserir errors al quadre | ||
errorMessagesDiv.classList.remove("hidden"); // Mostrar el contenidor | ||
event.preventDefault(); // Evitar l'enviament del formulari | ||
} | ||
} | ||
|
||
// Assignar l'esdeveniment submit al formulari | ||
document | ||
.getElementById("treeForm") | ||
.addEventListener("submit", validateFormTreeType); |