switchery
switchery copied to clipboard
Cannot set checked after ajax build of page
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
Same, i can t update my checkbox with values get in ajax call (async).
$("#cb_25").attr("checked", true); switchery.handleOnchange();
@pisgo handleOnChange fires the associated onChange-Method, maybe not this, what somebody want