Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Keeping modal open if validation fails in Laravel

I have a view that pops up a modal when the user clicks add a record. There is a field for the mileage of the user's car so the user can enter their starting mileage and ending to calculate the mileage covered. When a user inputs a value for the ending mileage and that value is lower than the starting mileage and submits the modal, the record does not get stored but the field is highlighted when the modal is opened again. I want to make sure the user sees the error before they submit or when they submit, it should show the error in the modal without them having to open it again. Is there any way to do this?

The code I tried for showing the error:

Controller:

 $request->validate([
            'start_odo' => 'required',
            'end_odo' => 'required|gt:start_odo',
        ]);

View:

<div class="mb-3">
                <label for="recipient-name" class="col-form-label">End ODO</label>
                <input type="number" style="width: 7em" name="end_odo" class="form-control @error('end_odo') is-invalid @enderror" id="end_odo" min="0"  required>
                @error('end_odo')
                <span class="invalid-feedback">{{ $message }}</span>
            @enderror
              </div>

JS that I tried:

<script type="text/javascript">
  function validate()
  {
      var value1;
      var value2;
    
      value1 = parseFloat(document.getElementById('start_odo').value);
      value2 = parseFloat(document.getElementById('end_odo').value);
      if (value2 > value1)
      {
          //we're ok
      }
      else
      {
          alert("Values are not as they should be");
          return false;
      }
  }
</script>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda