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

209
Vistas
bootstrapSwitch Don't toggle switch on click

I have a bootstrap switch, but I don't want it to toggle everytime. I want to check that a condition is true, and only then toggle the switch. How can I do that? This is what I have so far:

$("[name='relVal']").bootstrapSwitch({
    onSwitchChange: function(event, state) {
       if (condition_is_met) {
          $("[name='relVal']").bootstrapSwitch('state', true);
       }
    }
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From the docs:

onSwitchChange

Callback function to execute on switch state change. If false is returned, the status will be reverted, otherwise nothing changes

So all you need to do is return true/false for the switch to actually happen or not.

$("[name='relVal']").bootstrapSwitch({
    onSwitchChange: function(event, state) {
        if (condition_is_met) {
            return true;
        }

        return false;

        // Or as a one-liner
        // return condition_is_met;
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
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