Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Create ON/OFF Switch #1935
Comments
|
I've been thinking about adding just such a feature. We'll see if we can get to it. |
huzzi
commented
Feb 13, 2012
|
+1 |
dbpolito
commented
Feb 13, 2012
|
|
Anahkiasen
commented
Feb 13, 2012
|
+1 for this feature, currently I've replaced entries with only two choices by togglable buttons in my forms, but on/off switches would be far more user-friendly and consistent with today's interfaces. |
Nerian
commented
Feb 13, 2012
|
+1 Would be really useful |
|
Maybe something like the jQuery Mobile implementation (uses the select input) |
jhajduk
commented
Feb 14, 2012
|
+1 |
jbranchaud
commented
Feb 15, 2012
|
+1, great idea! |
g00fy-
commented
Feb 15, 2012
|
+1 |
thomshouse
commented
Feb 15, 2012
|
+1! |
jlxw
commented
Feb 17, 2012
|
+1! |
jlxw
commented
Feb 17, 2012
|
whats the best solution now? checkbox? |
adetwiler
commented
Feb 17, 2012
|
@jlxw For right now I am using the Radio buttons: |
thomshouse
commented
Feb 17, 2012
|
I've created a very simple proof-of-concept using a single checkbox. Emphasis on proof-of-concept... It's not good for much else beyond that, but I think it gets the point across: Edit: A variation (CSS transition is Webkit only): http://jsfiddle.net/76mxJ/2/ |
|
@adetwiler, @jlxw Here's a working example of toggle buttons I use instead of the current implementation which is, IMHO, more semantically correct and works out of the box with form inputs. |
tuladhasum
commented
Feb 17, 2012
|
+1 |
thomshouse
commented
Feb 18, 2012
|
Been fiddling a bit more... (Hey, now I know why it's called jsfiddle.) This one is CSS-only, no JS required: |
|
Here's a moz working version http://jsfiddle.net/charettes/76mxJ/4/ |
thomshouse
commented
Feb 18, 2012
|
...and again with sliding animations. Now with moz compatibility too: I am going to try to fork and add this feature this weekend, if people like my work so far... and if I have the patience to figure out the build process. :D |
|
@thomshouse thanks for the idea here's a no JS required working toggle buttons http://jsfiddle.net/charettes/SauLj/ |
quasipickle
commented
Feb 26, 2012
|
This is a great control idea, but in most implementations it's limited to only being a switch between opposites (on/off, yes/no). I've used this type of control in situations where there are only 2 options, but they are not obvious opposites, ie: any/all. If this control were added, I would like to see it added in such a way that both options are visible . |
victorhooi
commented
Feb 26, 2012
|
Hi, I'd love to see something like this as well =). @thomshouse @markdotto: Is there any word on this getting into Bootstrap officially? Cheers, |
thomshouse
commented
Feb 27, 2012
|
@victorhooi Sorry, I got sidetracked last weekend and haven't had a chance to come back to this. |
add1ct3dd
commented
Mar 13, 2012
|
+1 |
trask
commented
Mar 13, 2012
|
+1 |
hacfi
commented
Mar 23, 2012
|
I started working on a form plugin to replace select dropdowns, checkbox and radio icons last night...will publish the repo in a week or two. However, I don't think this should be part of the bootstrap "core". @markdotto have you thought about a additional plugin repository or page? |
timburgess
commented
Mar 27, 2012
|
+1 |
lastguest
commented
Apr 24, 2012
|
+1 |
younes0
commented
Apr 25, 2012
|
+1 |
JoeConyers
commented
Apr 25, 2012
|
+1 |
auzigog
commented
May 6, 2012
|
+1 |
richardp-au
commented
May 17, 2012
|
Here's a few versions that I've been working on. They support all of Bootstrap's standard colours (just like buttons, labels, etc.).
Number 4 is looking the best and works almost perfectly in Safari, Chrome and IE9 (obviously IE9 doesn't have any gradients and I haven't checked Firefox yet). Unfortunately, IE7 and 8 aren't looking so great since they lack support for the Please let me know what you guys think. |
richardp-au
commented
May 18, 2012
|
Ok, I've revised my switch and here's my latest:
This version requires minimal HTML and uses the data-api to create the necessary child In addition, you can use the I have also added a Please help me test the jsFiddle. I've found it works in Safari, Chrome, IE9, IE8 (no rounded corners of course), IE7 (doesn't have the text though) and Firefox (I found the CSS transitions were a bit out of sync though). I've included the LESS inside a comment this time too. @markdotto and @fat: Please let me know what you think of this so far. |
dbpolito
commented
May 18, 2012
|
@R1ch0 Seems pretty good to me. Great work! |
cfletcher1856
commented
May 18, 2012
|
@R1ch0 |
add1ct3dd
commented
May 18, 2012
|
They look good, but for me way too large/rounded. |
richardp-au
commented
May 18, 2012
|
@add1ct3dd: they're the same size as Apple's ones on iOS. |
thomshouse
commented
May 20, 2012
|
Please excuse the crudity of this model... ;) I'm too exhausted to really pretty it up right now, but here's a new mock-up based on a combination of my old one and some of the others I've seen here: http://jsfiddle.net/VEW2K/ A rundown:
I have not tested it in IE or Firefox, and I was not able to get CSS transitions working on the :before and :after pseudo content, so maybe someone else will have better luck. But I think it's cleaner than my old test, and I prefer a non-JS solution personally. |
richardp-au
commented
May 20, 2012
|
@thomshouse That won't work on IE 7 and 8 for the same reasons my earlier attempts didn't work. Both IE 7 and 8 don't support the The other problem is the IE7 doesn't support Refer to http://www.quirksmode.org/css/contents.html#CSS3 for compatibility. |
thomshouse
commented
May 21, 2012
|
@R1ch0 That's why I said it should degrade gracefully. :P The I guess the correct term would be "progressive enhancement"? Old browsers show the stock chrome, new browsers will show the customizations. Same concept behind the |
richardp-au
commented
May 21, 2012
|
@thomshouse Ok so I missed that point :) However, if it's possible to to make it work on an old browser (which it is with JS), then wouldn't that be better? It's no different from BS's buttons which require JS for the checkbox or radio modes. Also, when using the data API, you don't actually have to type any JS so I don't really think it's a problem having JS in there. |
thomshouse
commented
May 21, 2012
I guess that's a decision best left for @fat and @markdotto. They have a better understanding of the principles behind Bootstrap's than I could ever hope to have. :) It could be done both ways, too... CSS-only for the browsers that support it, JS-based for the others. I guess we'll know when we see what makes it into 2.1. |
pixelyunicorn
commented
May 27, 2012
|
I also think that there should be a disabled state, a middle state, and different sizes along with an option for square edges... (iOS 4/earlier-like) |
richardp-au
commented
May 28, 2012
|
I would like to add a disabled state to mine. As for a "middle" state, I'm not sure it's appropriate to this type of switch. Also, if it's modelled of something like iOS (as mine are), then it probably wouldn't be a good idea to change an already very common UI element in this way. I suppose different sizes could be doable in a similar fashion to buttons. The current size (of mine once again) is the same as iOS's and also the same height as BS's text fields. Lastly, I don't see any reason to have an option for square buttons. If you want them, you can always change the border radius yourself. This applies to other elements too, such as badges. |
raduluchian
commented
Jun 6, 2012
|
+1 |
marshallbu
commented
Jun 6, 2012
|
+1 |
Fabs
commented
Jun 6, 2012
|
+1 |
cemo
commented
Jun 7, 2012
|
+1 for 2.1.0 |
sbert
commented
Jun 7, 2012
|
+1 |
shaneog
commented
Jun 13, 2012
|
|
gilbert
commented
Jun 13, 2012
|
@charettes has the best solution, in my opinion: http://jsfiddle.net/charettes/SauLj/ |
raduluchian
commented
Jun 13, 2012
|
@mindeavor That solution is already available in Bootstrap under Javascript Plugins > Button. |
gilbert
commented
Jun 13, 2012
|
@raduluchian True, but it requires javascript, and doesn't have radio button markup. @charettes 's solution requires no javascript and only a little css. |
nijikokun
commented
Jun 13, 2012
|
I've created a solution for this and its an actual on/off switch and visually matching of bootstrap. I will be releasing it in a moment. |
nijikokun
commented
Jun 13, 2012
|
Actually just everyone: |
richardp-au
commented
Jun 14, 2012
|
@mindeavor The solution you refer to (from @charettes) won't work in IE 7 and 8 because it uses |
|
@R1ch0 @mindeavor, as discussed in #2284 it would be possible to add a shim for IE 7 and 8. @kwilliams did a great job there. |
thomshouse
commented
Jun 14, 2012
|
Since we're getting all fancy... :P I actually like a lot of things about @nijikokun's version, but I think a flat color would look better for the recessed area. I also feel like there's something "off" about the widths, but I can't place it... As for new features, thought it would be nice to be able to use the .spanX classes for special sizes. |
nijikokun
commented
Jun 14, 2012
|
@thomshouse if you happen to fork mine and add that functionality I'll accept the pull request, if not, i'll probably add it in later. Also, the flat colors are nice, but I think it should be optional, maybe a .flat class. |
Garbee
commented
Jul 28, 2012
|
+1 |
tobsn
commented
Aug 2, 2012
|
+1 |
richardp-au
commented
Aug 2, 2012
Seriously? Can people not read? |
Dentxinho
commented
Aug 2, 2012
|
@nostalgiaz nice one! Thumbs up to @R1ch0's too! |
nostalgiaz
commented
Aug 2, 2012
|
@Dentxinho thanks :) Do you need some new features? |
Dentxinho
commented
Aug 2, 2012
|
@nostalgiaz having options to set the transition speed would be great ;) |
nostalgiaz
commented
Aug 2, 2012
|
@Dentxinho can you open me an issue? :) |
Dentxinho
commented
Aug 2, 2012
|
@nostalgiaz done =) |
johnlabu
commented
Aug 3, 2012
|
+1 |
johnaschroeder
commented
Aug 3, 2012
|
+1 |
abestic9
commented
Aug 7, 2012
|
This is my (in production use) solution, but I may consider the jsFiddles from r1ch0: http://jsfiddle.net/abestic9/GQnFA/ Simply a grouped button set, all standard bootstrap classes can be applied (I use btn-mini in some areas, for example) |
|
Hey guys ! First of all thanks a lot @R1ch0 for your amazing switchs ! I had a problem w/ the change event not triggered for the checkbox when clicking the switch (switch number 5) so i changed line 34 of the js file and it now looks like that : this.$checkbox && this.$checkbox.attr('checked', $el.hasClass(active)) && this.$checkbox.trigger('change')Hope i helped ! |
richardp-au
commented
Aug 14, 2012
|
Thanks for the heads up @Intrepidd. I haven't actually needed to use the switches yet so I haven't done a lot of testing on them. I have thought of some changes I'd like to make if I ever get the chance. As far as your change, you could simplify it a little: this.$checkbox && this.$checkbox.attr('checked', $el.hasClass(active)).trigger('change') |
|
Indeed, i forgot that |
ghost
commented
Aug 14, 2012
|
+1 |
calvinjuarez
commented
Aug 14, 2012
|
+1 |
jeronimonunez
commented
Sep 12, 2012
|
+1 |
nostalgiaz
commented
Sep 12, 2012
|
This is my solution, I pushed the latest update an hour ago... Open me an issue if you have some suggestions or if you wanna report bugs. Hope you like it :) |
jeronimonunez
commented
Sep 12, 2012
|
@nostalgiaz Looks good but it would be perfect if it were working like JQM toggle switch component: http://jquerymobile.com/demos/1.2.0-pre/docs/forms/switch/ |
nostalgiaz
commented
Sep 12, 2012
|
@jeronimonunez open me an issue, ok? |
jeronimonunez
commented
Sep 12, 2012
|
@nostalgiaz done! ;) |
nostalgiaz
commented
Sep 13, 2012
|
@jeronimonunez ok! I've just released my 2.0 bootstrap toggle buttons! Do you like it? |
jeronimonunez
commented
Sep 14, 2012
|
@nostalgiaz looks really good! I'm going to test it on android and ios, I'll tell you if there's any issue. |
nostalgiaz
commented
Sep 14, 2012
|
@jeronimonunez thanks :) |
skyrpex
commented
Oct 15, 2012
|
Any chances that @nostalgiaz solution will be integrated into the bootstrap? |
nostalgiaz
commented
Oct 15, 2012
|
@skyrpex wow! It would be great! I made a branch called feature/boostrap where you can find the first implementation of a possible version for bootstrap... but before investing more time I would like some feedback from them |
stevenwong
commented
Oct 16, 2012
|
@nostalgiaz solution looks good, but doesn't work with Zepto unfortunately. Zepto just doesn't completely replicate what jQuery does. I.e. .data() and .data('name', object) won't work. $element.find('>div') and $.extend(true, ...) only supported in the master. Can't use this for my mobile project yet I suppose |
nelsonad
commented
Oct 16, 2012
|
Here's what I'm doing: http://jsfiddle.net/6KCzE/ |
fission6
commented
Nov 1, 2012
|
@nostalgiaz this is nice stuff, great work - someone pull this into bootstrap! |
nostalgiaz
commented
Nov 1, 2012
|
@fission6 thank you :) |
stefanozoffoli
commented
Nov 15, 2012
|
This would be awesome: http://www.chrisnorstrom.com/2012/11/invention-multiple-choice-windowed-slider-ui/ |
|
I've been back and forth with this a lot and I think for now we'll punt on this. That said, do checkout Ratchet and see if you can port their switch. For now, as this falls under custom form elements, we won't be adding it. |
mdo
closed this
Nov 30, 2012
ghinda
commented
Nov 30, 2012
|
I've just finished work on the latest version of my own CSS-only accessible toggle switches, and the latest version also adds full support for Bootstrap and Foundation. They support both checkboxes and radios. You can check it out here: It's really flexible and can use a number of classes from Bootstrap, for both the track and the sliding button. |
nostalgiaz
commented
Nov 30, 2012
|
This is my initial solution for an easy-to-use switch (using the @mdo 's guidelines) Here you can find the code: https://github.com/nostalgiaz/bootstrap-switch and here the demo: http://www.larentis.eu/switch/ |
marstone
commented
Jan 29, 2013
|
+1 |
t3hnar
commented
Feb 19, 2013
|
+1 |
yagudaev
commented
Feb 20, 2013
|
@nostalgiaz great job! That looks great, thanks for the hard work :). Looking forward to using this one. |
nostalgiaz
commented
Feb 20, 2013
|
@yagudaev thanks! |
This was referenced Feb 21, 2013
|
You may take a look at this one: iOS 6 switch style checkboxes with pure CSS Example and code here |
ChinaXing
commented
Mar 19, 2013
|
+1 |
marcotisi
commented
Apr 5, 2013
|
+1 |
leettastic
commented
Apr 5, 2013
|
+1 |
phptux
commented
Apr 11, 2013
|
+1 |
DmitryEfimenko
commented
Apr 23, 2013
|
+1 |
cezarlz
commented
Apr 30, 2013
|
+1 |
Madlord
commented
May 8, 2013
|
+1 |
JasPanesar
commented
May 11, 2013
|
+1 |
unematiii
commented
May 12, 2013
|
+1 |
marclaporte
commented
May 13, 2013
|
+1 |
henrywright
commented
Jun 9, 2013
|
+1 |
coderdave
commented
Jul 11, 2013
|
+1 |
ZacharyDraper
commented
Jul 29, 2013
|
+1 |
DrWeir
commented
Aug 3, 2013
|
+1 |
brunomac
commented
Aug 3, 2013
|
+1 Bruno Machado On 03/08/2013, at 13:33, Weir notifications@github.com wrote:
|
cvrebert
locked and limited conversation to collaborators
Jun 9, 2014
|
i'd be careful, regardless which one is proposed, that it needs keyboard focus indication and a proper label... |
adetwiler commentedFeb 13, 2012
Not sure if anyone has mentioned this or not, but it would be cool to have something like this:
http://papermashup.com/demos/ajax-switch/