Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
react-bootstrap Form component
/** @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;
@mathieumg
Copy link

mathieumg commented Aug 28, 2014

I think lines 22 and 23 should be in braces?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment