views:

605

answers:

3

Hey guys, I'm looking for a nice tri-state checkbox controller in JS ? Got anything to recommend me?

The states I'm looking for are

  1. Checked
  2. Unchecked
  3. Indifferent (Was never checked/unchecked)
+1  A: 

Use radio buttons.

<input type="radio" name="tristate" value="checked" />Checked
<input type="radio" name="tristate" value="unchecked" />Unchecked

If none if the radios are turned on, then you have your third "indifferent" or null state.

Peter Di Cecco
My employer requires a checkbox control, it's a must for the UI
Yarin Miran
If it must be a checkbox, maybe you could incorporate the disabled functionality. ex. If a parent item's checkbox wasn't checked then the checkbox could be disabled on the child to represent the indifferent state. Of course, this doesn't work if you need to be able to change the child's state before the parent is set.
Peter Di Cecco
+1  A: 

You may want to look into EXTJS.

They have a big community that often builds things like this and I'm sure if you googled for one it might come up. Actually here you go you may be able to make a few changes to this and get it to work how you want:

http://extjs.net/forum/showthread.php?t=28096

Hope this helps!

Wade
A: 

If you need more than two states, then use 3 radio buttons.

Don't assume if the user didn't select anything to mean the third state. What if the user missed the question all together, or hit submit by mistake?

If you want 3 states, then have 3 states!

Pyrolistical
See comment on main thread.
Yarin Miran