Created
August 17, 2014 05:04
-
-
Save ronny/64776de35360f2960405 to your computer and use it in GitHub Desktop.
ReactJS CheckBox component that works like Rails' `f.check_box`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require('underscore') | |
React = require('React') | |
{span, input} = React.DOM | |
# Check box that always submits a value, even if unchecked. This uses the same | |
# trick as Rails's `f.check_box`: a hidden input with the same name as the | |
# checkbox but with a value of 0 that appears before the actual checkbox. When | |
# the checkbox is checked, the checkbox's value will be submitted, when it's | |
# unchecked, then the hidden input value of 0 will be submitted. | |
window.CheckBox = React.createClass | |
render: -> | |
(span {}, | |
(input {type: 'hidden', name: @props.name, value: 0}) | |
(input _.extend({}, @props, {type: 'checkbox', value: 1}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment