Skip to content

Instantly share code, notes, and snippets.

@syllog1sm
Created August 28, 2014 15:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syllog1sm/8ed7b64d53b7eee9eb1b to your computer and use it in GitHub Desktop.
Save syllog1sm/8ed7b64d53b7eee9eb1b to your computer and use it in GitHub Desktop.
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

I think lines 22 and 23 should be in braces?

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