[explorev2] Fields can validate input and handle errors (#1980)

As a result here, TextField does its own validation and now casts
the values it sends to Int or Float if set to do so.
This commit is contained in:
Maxime Beauchemin
2017-01-13 16:25:37 -08:00
committed by GitHub
parent 99b84d2909
commit a96024d0e7
3 changed files with 55 additions and 18 deletions

View File

@@ -42,8 +42,11 @@ export default class FieldSet extends React.PureComponent {
this.validate = this.validate.bind(this);
this.onChange = this.onChange.bind(this);
}
onChange(value) {
const validationErrors = this.validate(value);
onChange(value, errors) {
let validationErrors = this.validate(value);
if (errors && errors.length > 0) {
validationErrors = validationErrors.concat(errors);
}
this.props.actions.setFieldValue(this.props.name, value, validationErrors);
}
validate(value) {