【发布时间】:2016-08-24 13:48:39
【问题描述】:
我有一个经过验证的 redux 表单。当验证无误返回时,默认会在handleSubmit()中提交给控制器。
class SomeComponent extends Component {
constructor(props) {
super(props)
}
render() {
const { handleSubmit, fields: { field }, submitting, values } = this.props;
return (
<form onSubmit={handleSubmit(this.props.someActionForm)}>
<TextField {...field.input}
type="text"
label="FIELD"
floatingLabelText="FIELD"
errorText={field.touched? field.error: null}
/>
<div className="col-xs-12">
<FlatButton
label="ACTIVATE"
fullWidth={true}
style={styles.fullButton}
backgroundColor="#4FCDCC"
hoverColor="#59e5e3"
type="submit"
disabled={submitting}
/>
</div>
</form>
);
}
}
function validate(values) {
const errors = {};
if(!values.field) {
errors.field= "Field must not be empty !!!";
}
return errors;
}
SomeComponent = reduxForm({
form: "SomeComponent",
fields: ['field'],
validate
}, mapStateToProps, mapDispatchToProps )(SomeComponent);
如何添加一个函数,例如在验证成功但表单提交到操作之前触发的加载元素(handleSubmit())?
提前谢谢你
【问题讨论】:
-
在提交处理程序中有验证函数,并在验证为真后调用
this.props. handleSubmit
标签: node.js reactjs redux material-ui redux-form