switchery icon indicating copy to clipboard operation
switchery copied to clipboard

Cannot set checked after ajax build of page

Open pithhelmet8669 opened this issue 7 years ago • 3 comments

I build out the values of a column in a table based on the results from an ajax call.

I give each row a unique ID...

<input id="cd_25" type="checkbox" class="js-switch" />

and i use the sample behavior to apply the styles...

 var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
 elems.forEach(function (html) {
 var switchery = new Switchery(html, {size: 'small'});
 });

Now, i need to set the checked/unchecked value of one of the switchery checkboxes.

When i set the value at design time...

 <input id="cd_25" type="checkbox" class="js-switch" checked />

the switch is set correctly and displayed correctly

but when i try to set the checked prop or attr of the element, it is not being reflected on the browser.

//  $("#cb_25").prop("checked", true);    //failed
//  $("#cb_25").attr("checked", true);     //failed
  var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
  elems.forEach(function (html) {
    var switchery = new Switchery(html, { size: 'small' });
  });

Please advise if this is a bug

pithhelmet8669 avatar Mar 28 '17 19:03 pithhelmet8669

Same, i can t update my checkbox with values get in ajax call (async).

Magderidon avatar Sep 14 '17 18:09 Magderidon

$("#cb_25").attr("checked", true); switchery.handleOnchange();

pisgo avatar Dec 22 '17 07:12 pisgo

@pisgo handleOnChange fires the associated onChange-Method, maybe not this, what somebody want

GitToTheHub avatar Feb 26 '19 16:02 GitToTheHub