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

Clicking label not working as expected #312

Closed
plribeiro3000 opened this issue May 24, 2014 · 10 comments
Closed

Clicking label not working as expected #312

plribeiro3000 opened this issue May 24, 2014 · 10 comments
Assignees
Labels
Milestone

Comments

@plribeiro3000
Copy link

Hi. The new version @LostCrew release handles clicks on the label. But im facing a weird behavior, if the label is on the right side, it does not change the button, but does trigger the event and everything else work as expected.

I have a simple example on fiddle : http://jsfiddle.net/plribeiro3000/aL835/1/

@plribeiro3000
Copy link
Author

I have updated the code to show something i have noticed: http://jsfiddle.net/plribeiro3000/aL835/3/

If you look at the console you will the event being triggered twice. Is this behavior expected?

@LostCrew LostCrew self-assigned this May 25, 2014
@LostCrew
Copy link
Member

good morning @plribeiro3000,
thank your for the detailed case. can you update the jsfiddle with the version 3.0.1? you have to copy/paste it since it's been released yesterday and not available on cdn yet.

@plribeiro3000
Copy link
Author

Good morning @LostCrew !
Im already using the last version. I have uploaded it to a server and referenced it from there. =)

@plribeiro3000
Copy link
Author

@LostCrew LostCrew added bug and removed pending labels May 26, 2014
@plribeiro3000
Copy link
Author

I found that https://github.com/nostalgiaz/bootstrap-switch/blob/master/src/coffee/bootstrap-switch.coffee#L236 is triggering the event again if the input is a radio and the event did not turned the switch on.

Is that the behavior expected? or should it act like normal radio buttons?

@plribeiro3000
Copy link
Author

My bad, it acts like a normal radio button by doing nothing if you click on a already selected option.
But it seems a bit weird when you are working with switchs, shouldn't it always change its state and set the other options the other state?

@LostCrew
Copy link
Member

LostCrew commented Jun 1, 2014

@plribeiro3000 can you update the bootstrap switch source of the jsfiddle according to the latest develop branch changes? i made a couple of optimizations and they might have implicitly solved this issue. thanks.

@LostCrew LostCrew added this to the 3.0.2 milestone Jun 1, 2014
@plribeiro3000
Copy link
Author

I have updated the source at plribeiro3000.com.br, but just in case i have update the jsfiddle as well.

New link : http://jsfiddle.net/plribeiro3000/aL835/6/

But the behavior still exists.

@psychonelo
Copy link

After hours of debugging JavaScript in firebug, I found that I can fix this by removing the 'for' attribute from the label:

var checkbox = $("<input type='checkbox' id='MyCheckbox'>").prependTo( $("body") );
checkbox.bootstrapSwitch();
var bootstrapSwitch = checkbox.data('bootstrap-switch');
bootstrapSwitch.$label.removeAttr("for");

Clicking a label with attribute for="MyCheckbox" will be handled by Firefox. Removing removing the 'for' attribute from the label stops Firefox from changing the checkbox value again.

@LostCrew
Copy link
Member

LostCrew commented Jun 9, 2014

@psychonelo @plribeiro3000 thank you very much for the collaboration. feel free to give the updated develop branch a ride and tell me.

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

No branches or pull requests

3 participants