ons-switch methods have changed?
So for the ons-switch, I used to do:
And this worked great. It appears the setChecked method was removed as it is no longer a valid function. Now I have to do:
if (switchVar === 'true') document.getElementById('switchID').setAttribute('checked',true); else document.getElementById('switchID').removeAttribute('checked');
Is this the proper method or am I missing something very basic here?
@munsterlander You can also do it with the
checkedproperty if I don’t remember wrong. Try
document.getElementById('switchID').checked = true.
@Fran-Diox I tried that and it returns function checked is not a valid function.
IliaSky last edited by
document.getElementById('switchID').checked = (switchVar === 'true');
This should do it. If it doesn’t work it may be some sort of timing issue.
@IliaSky and @Fran-Diox So that worked. I don’t know why when I initially did as @Fran-Diox suggested it gave me that error. I reset the project and wrote it out as @IliaSky suggested and it worked - it’s the exact same code, just a different right-side assignment. Oh well, working now with minimal code. Thanks!