首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >actions.submit和actions.submitFields有什么区别?

actions.submit和actions.submitFields有什么区别?
EN

Stack Overflow用户
提问于 2018-02-14 23:07:43
回答 1查看 141关注 0票数 0

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(“特性”)

它实际上提交的表单具有与我的按钮完全相同的行为。

代码语言:javascript
复制
<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,因此您可以分派该操作,这样您就可以提交表单,而无需单击要提交的按钮。

我漏掉什么了吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-15 01:16:54

从ts文档中可以看出,一个字段按字段处理验证/错误,而常规提交则对整个表单进行验证/错误添加:

代码语言:javascript
复制
/**
 * 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://github.com/davidkpiano/react-redux-form/blob/684f75342a43a3e8bd46b07d1baf8248ae23db98/react-redux-form.d.ts#L949

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48797727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档