Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap switch setState gives js error

I am trying to change state of bootstrap switch with condition return value from Ajax,

HTML,

<input type="checkbox" id="limit" class="make-switch"  data-on-text="Yes" data-off-text="No" data-on="success" data-on-color="success" data-off-color="danger" data-size="small">

<input type="text" name="limit_amount" id="limit_amount" autocomplete="off"  class="form-control"  readonly>


if(objData.limit === 'Yes')
{
  $('#limit').bootstrapSwitch('setState', true);
  $("#limit_amount").prop("readonly", false);
}
else {
    $('#limit').bootstrapSwitch('setState', false);
    $("#limit_amount").prop("readonly", true);
}

But it throw error as below .. Uncaught TypeError: Cannot read property 'apply' of undefined

Uncaught TypeError: Cannot read property 'apply' of undefined
at HTMLInputElement.<anonymous> (bootstrap-switch.min.js:22)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.e.fn.bootstrapSwitch (bootstrap-switch.min.js:22)
at Object.success (limitingcat.js:311)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)

Is this bug of something wrong?

like image 984
rjcode Avatar asked Dec 19 '16 10:12

rjcode


1 Answers

Try this ;)

As far as I can tell the method has been updated (but not well documented).

$('#limit').bootstrapSwitch('state', true);
$('#limit').bootstrapSwitch('state', false);

https://stackoverflow.com/a/35375128/2922854 by @bplittle

like image 141
itzmukeshy7 Avatar answered Nov 04 '22 10:11

itzmukeshy7