The initial state of the switchery is always false when it is obtained by Javscript / jQuery code, when the page is loaded or rendered having this checked / unchecked value preset in the HTML code.
I want to retrieve the current state (checked / unchecked) to use in a validation of data entered into a form.
Javascript / Jquery 3.2.1
if( $('#checkIsIndoor').prop('checked')===true) {
if ( $("#inputHeight").val().trim() === '' ){
showError('inputHeight', 'As it is an Interior Meeting Space you must enter the height in meters.');
todoOk = false;
}
else{
clearErrors('inputHeight');
}
}
HTML
<div class="form-group">
<label>
<input id="checkEsInterior" name="esInterior" type="checkbox" class="js-switch" checked="" data-switchery="true" style="display: none;"> Es Interior?
</label>
</div>
However, after clicking on the Switchery and re-executing the code that gets the value of the Switchery / Checkbox, the value is correct.
The only thing that works for me correctly and should not be is:
if ($("#checkEsInterior + span.switchery-default").css('background-color')=="rgb(38, 185, 154)"){
if ( $("#inputHeight").val().trim() === '' ){
showError('inputHeight', 'As it is an Interior Meeting Space you must enter the height in meters.');
todoOk = false;
}
else{
clearErrors('inputHeight');
}
}
The color rgb (38, 185, 154) is the checked status color of the Switchery by default.
Why does this happen?
The initial state of the switchery is always false when it is obtained by Javscript / jQuery code, when the page is loaded or rendered having this checked / unchecked value preset in the HTML code.
I want to retrieve the current state (checked / unchecked) to use in a validation of data entered into a form.
Javascript / Jquery 3.2.1
HTML
However, after clicking on the Switchery and re-executing the code that gets the value of the Switchery / Checkbox, the value is correct.
The only thing that works for me correctly and should not be is:
The color rgb (38, 185, 154) is the checked status color of the Switchery by default.
Why does this happen?