Estoy tratando de asegurarme de que todos los campos sean obligatorios, pero este código solo funciona en las etiquetas de "entrada", pero no en las etiquetas de selección y área de texto.
Cualquier ayuda será apreciada. ¡Gracias!
AQUÍ ESTÁ MI HOJA
<div class="tab"> <div class="form-group mb-3"> <select name="currency" class="choices form-control" id="devise{{ Auth::user()->cred->id }}" onchange="deviseSelect({{ Auth::user()->cred->id }})" required="true"> <option value="" selected disabled>choose</option> <option value="USD">USD</option> <option value="FC">FC</option> </select> </div> </div>AQUÍ ESTÁ MI JAVASCRIPT PARA LA ETIQUETA HTML "SELECCIONAR"
<script> var currentTab = 0; // Current tab is set to be the first tab (0) showTab(currentTab); // Display the current tab function validateSelect() { // This function deals with validation of the form fields var x,z, i, valid = true; x = document.getElementsByClassName("tab"); z = x[currentTab].getElementsByTagName("select"); // A loop that checks every select field in the current tab: for (i = 0; i < z.length; i++) { var option = z.options[i]; // If a field is empty... if (option.value == "") { // add an "invalid" class to the field: z[i].className += " required"; // and set the current valid status to false: valid = false; } } // If the valid status is true, mark the step as finished and valid: if (valid) { document.getElementsByClassName("step")[currentTab].className += " finish"; } return valid; // return the valid status } </script>ENCONTRÉ DONDE ME EQUIVOQUE
Acabo de cambiar algo dentro del ciclo for y todo comenzó a funcionar perfectamente.
<script> for (i = 0; i < z.length; i++) { // If a field is empty... if (z[i].value == "") { // add an "invalid" class to the field: z[i].className += " is-invalid"; // and set the current valid status to false: valid = false; } } </script>