Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it a bug? - I can not get the correct state of the switchery when loading the page for the first time #164

Open
martinmurciego opened this issue Jul 21, 2018 · 0 comments

Comments

@martinmurciego
Copy link

martinmurciego commented Jul 21, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant