Closed danieljuhl closed 9 years ago
this.state.value
contains an array of strings (the correct values), but this.refs
is empty, and therefore failing.
The List
factory expects an array of sub-factories, one for each element in this.state.value
. You can override this behaviour defining a custom factory:
class MyList extends t.form.List {
validate() {
return new t.ValidationResult({
errors: [], // <= your custom validation logic here...
value: this.state.value
});
}
}
var options = {
factory: MyList
};
var Schema = t.list(t.String);
var App = React.createClass({
onSubmit(evt) {
evt.preventDefault();
var value = this.refs.form.getValue();
if (value) {
console.log(value);
}
},
render() {
return (
<form onSubmit={this.onSubmit}>
<t.form.Form
ref="form"
type={Schema}
options={options}
/>
<button type="submit" className="btn btn-primary">Save</button>
</form>
);
}
});
Thanks - that was the right direction. I got it working now.
I have encountered an issue with
this.refs.form.getValue()
triggering validation on a custom List template, which has a nested structure, where the values is flattened before returned back ingetValue()
.The errors occurs here:
How do I assign a correct ref to each of my entries in the nested structure, or how to ignore this validation?