-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
state and checked not working at all #392
Comments
Hi @Goeny, |
If i understand correct, the switch state should be "off" (or false) if the "checked" attribute is not set. When i try that in (i.e.) Fiddle. It does exactly what it should do. State is true when "checked" is set, state is false when "checked" is not set. <?php if($data['welkom_aan'] == 1){ echo 'checked'; } ?> does exactly that. For some reason, the switch state is always true. Even when i set default state to false, when "checked" is set or not. I have added Could it be a conflict with some other js? |
i got the same problem but it happens when i try to create the bootstrap switch inside a not visible bootstrap tab. using i have tried to replicate this error in jsflidder but what happens there is that the swich renders with errors: |
I think the problem is indeed because of the tabs. I am using it in tabs aswell. Copied that part to jsfiddle. Doesnt work there either. The switch can be found in [Afbeeldingen] and [Website]=>[Welkomst bericht] |
I think the issue is that bootstrap-switch prefers the 'value' attribute over all other values. Link to the line would be here. In my opinion, setting the data-state attribute should trump the value attribute. I think what most people here are trying to accomplish is to send an empty value when the checkbox is off and a different value when it is on - I have a group of switches that feed one array in the POST data. Another common practice used (also in my code in another instance of this same issue) is to use a hidden field first and then have the checkbox, both with the same 'name' attribute. That way, the value always shows up in the POST data, regardless of whether the checkbox is checked or not. |
I actually do use a hidden input field with the same name to give the "switch" a 0 value when switched off and a 1 value when switched on. |
Actually, I'm not sure it's the hidden field. Adding some example code: <input id="field_1" class="bootstrap-switch" name="field[]" value="2" data-state="false" type="checkbox" /> is incorrectly rendered as checked. <input name="manageraccess" value="0" type="hidden">
<input id="manageraccess" class="bootstrap-switch" name="manageraccess" value="1" data-state="0" type="checkbox"> is correctly rendered as unchecked. <input name="access" value="0" type="hidden">
<input id="access" class="bootstrap-switch" name="access" checked="checked" value="1" data-state="1" type="checkbox"> is correctly rendered as checked. |
I am using the same markup.
According to your example, this code should make the switch unchecked |
Hi, I have same problem :s |
Using bootstrap switch within Durandal + Knockout and experiencing this problem My binding was working fine and no longer works
Looks like the 'state' method is no longer registering the change, possibly due to the DOM not being loaded by the framework as per the above issue. |
add me to the list =( |
This is very odd. For me Here's a quick'n'dirty workaround. |
hi all, the problem occurs in |
develop fixes the problem for me with hidden tabs |
Please! I need the same fix for the @OlympicLarry's problem! |
For me, the issue happened all over the place - hidden, not hidden, didn't matter. Sorry, but time was a factor for me, so I switched to minhur/bootstrap-toggle. |
@daviddeutsch perhaps providing a fiddle of your issue would help for us that wish to keep using this wonderfull plugin. Otherwise it just comes off as a poor attempt to promote a different plugin. |
I tried doing that but lost more time. Again: Sorry, did not have the time to contribute but did want to share a solution that worked for me, even if it meant using a different plugin. |
@daviddeutsch fair enough, i respect your need of something that just works. feel free to give the coming |
fix is coming out with |
Confirmed fixed with 3.3.1, thanks :) |
yep! works also for me. |
Hi! switch is on but state is undefined! |
I want to use the switch with an ordinary checkbox
For some reason the checked attribute doesn't do a thing.
When changing the default state value to false it doesn't work either.
No matter what i try, the switch is always "on".
When checking the html using the element inspector (Chrome and FF) the output is what to be expected. But for some reason the state will not change.
The text was updated successfully, but these errors were encountered: