-
-
Save javereec/bfc1b90f6b37fb28f72d to your computer and use it in GitHub Desktop.
react-bootstrap Form component
This file contains 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
/** @jsx React.DOM */ | |
import React from './react-es6'; | |
import classSet from './react-es6/lib/cx'; | |
import BootstrapMixin from './BootstrapMixin'; | |
var Form = React.createClass({ | |
mixins: [BootstrapMixin], | |
propTypes: { | |
onSubmit: React.PropTypes.func, | |
}, | |
getDefaultProps: function() { | |
return {bsClass: "form"}; | |
}, | |
onSubmit: function(e) { | |
e.preventDefault(); | |
if (e.target.type == 'submit') | |
var v = this.getValues(); | |
this.props.onSubmit(v.values, v.checked, v.validation); | |
}, | |
render: function(){ | |
var className = "form"; | |
return this.transferPropsTo( | |
<form onClick={this.onSubmit} className="form" role="form" action="#"> | |
{this.props.children} | |
</form> | |
); | |
}, | |
getValues: function() { | |
var values = {}; | |
var checked = {}; | |
var validation = {}; | |
var child; | |
for (var i = 0; i < this.props.children.length; i++) { | |
child = this.props.children[i]; | |
if (child.getValue) | |
values[child.props.name] = child.getValue(); | |
if (child.getChecked) | |
checked[child.props.name] = child.getChecked(); | |
if (child.validationState) { | |
validation[child.props.name] = child.validationState(); | |
} | |
} | |
return { | |
'values': values, | |
'checked': checked, | |
'validation': validation | |
}; | |
} | |
}); | |
export default = Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment