Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!