ons-switch methods have changed?
-
So for the ons-switch, I used to do:
document.getElementById('switchID').setChecked((switchVar=== 'true'));
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
checked
property if I don’t remember wrong. Trydocument.getElementById('switchID').checked = true
.
-
@Fran-Diox I tried that and it returns function checked is not a valid function.
-
@munsterlander It became a simple boolean property of the switch - it’s not a function anymore. Demo (^_^)
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!