actions.submit()和actions.submitFields在redux forms中有什么区别?不幸的是,文件对这件事并不十分清楚。
我测试了这两个函数--我的表单名为“feature”,只有firstName和lastName输入框。
这就是我所做的:
1) actions.submit(“actions.submit.feature.firstName”,somePromise)
除了发送如下所示的rrf/addIntent操作之外,似乎什么也不做:
类型(引脚):"rrf/addIntent“模型(引脚):"feature.lastName”类型(引脚):“提交”
2) actions.submit(“特性”)
它实际上提交的表单具有与我的按钮完全相同的行为。
<button type="submit">
submit me!
</button>3) actions.submitFields(“actions.submitFields.feature.firstName”,somePromise)
与1相同)
actions.submitFields('feature') ( 4)
与2)相同
据我所知,actions.submit和actions.submitFields完全一样。
并且提供了actions.submit,因此您可以分派该操作,这样您就可以提交表单,而无需单击要提交的按钮。
我漏掉什么了吗?
谢谢!
发布于 2018-02-15 01:16:54
从ts文档中可以看出,一个字段按字段处理验证/错误,而常规提交则对整个表单进行验证/错误添加:
/**
* Waits for a submission promise to be completed, then, if successful:
* * Sets .submitted property of form for model to true
* * Sets .validity property of form for model to the response (or true if the response is undefined).
*
* If the promise fails, the action will:
* * set .submitFailed property of form for model to true
* * set .errors property of form for model to the response
*
* @param model The top-level model form key of the data to submit.
* @param promise The promise that the submit action will wait to be resolved or rejected
*/
submit: (model: string | ModelGetterFn, promise?: Promise<any> | undefined, options?: any) => ActionThunk;
/**
* Waits for a submission promise to be completed, then, if successful:
* * Sets .submitted property of form for model to true
* * Each key in the response, which represents a sub-model (e.g., "name" for users.name) will have its .validity set to its value.
*
* If the promise fails, the action will:
*
* * set .submitFailed property of form for model to true
* * Each key in the response, which represents a sub-model (e.g., "name" for users.name) will have its .errors set to its value. (See example)
*
* @param model (String | Function): the model to be submitted
* @param promise (Promise): the promise that the submit action will wait to be resolved or rejected
*/
submitFields: (model: string | ModelGetterFn, promise: Promise<any>) => ActionThunk;https://stackoverflow.com/questions/48797727
复制相似问题