Sha256: caf912941aa00bc92feeb7a7f5eae24841731111874e7249fbc296278ab6dd66
Contents?: true
Size: 1.31 KB
Versions: 15
Compression:
Stored size: 1.31 KB
Contents
// A form that works with stores to do AJAXy submission & backbone // validation Rev.registerComponent('StoreForm', class extends React.Component { constructor(props) { super(props) this.onSubmit = this.onSubmit.bind(this) } static get propTypes() { return { store: React.PropTypes.object.isRequired, path: React.PropTypes.string.isRequired } } static get mixins() { return [Rev.Mixins.StoreToModel] } get model() { return JSONPath({json: this.props.store, path: this.props.path})[0] } render() { return <Rev.Components.Form method="POST" onSubmit={ this.onSubmit } action={ this.formAction() } className={ this.props.className } encType="multipart/form-data" > { this.props.children } </Rev.Components.Form> } formAction() { if(this.props.action) { return this.props.action } return this.model.url() } formMethod() { if(this.props.method) { return this.props.method } if(this.model) { if(this.model.isNew()) { return 'POST' } else { return 'PATCH' } } return 'POST' } onSubmit(e) { this.props.store.resetErrors() e.preventDefault() this.props.store.save(this.props.path) } })
Version data entries
15 entries across 15 versions & 1 rubygems