Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #295 from wellyshen/feature/change-touched-fields-…
Browse files Browse the repository at this point in the history
…to-touched

Feat(useForm): rename the option of "setValues" from "touchedFields" to "touched"
  • Loading branch information
wellyshen authored Jan 2, 2021
2 parents eaadadd + 971180d commit 92289f1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-lions-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

Feat(useForm): rename the option of `setValues` from `touchedFields` to `touched`
4 changes: 2 additions & 2 deletions docs/api-reference/use-form.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ setValues(
{ firstName: "Welly", lastName: "Shen" }, // It will replace the entire values object
{
shouldValidate: true, // (Default = "validateOnChange" option) Triggers form validation
touchedFields: ["firstName"], // Sets fields as touched by passing their names
// touchedFields: (allFieldNames) => allFieldNames, // A reverse way to set touched fields
touched: ["firstName"], // Sets fields as touched by passing their names
// touched: (allFieldNames) => allFieldNames, // A reverse way to set touched fields
dirtyFields: ["firstName"], // Sets fields as dirty by passing their names
// dirtyFields: (allFieldNames) => allFieldNames, // A reverse way to set dirty fields
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface SetValues<V> {
values: ValuesArg<V>,
options?: {
shouldValidate?: boolean;
touchedFields?: string[] | FieldNamesFn;
touched?: string[] | FieldNamesFn;
dirtyFields?: string[] | FieldNamesFn;
}
): void;
Expand Down
2 changes: 1 addition & 1 deletion src/types/react-cool-form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare module "react-cool-form" {
values: V | PreviousValuesFn<V>,
options?: {
shouldValidate?: boolean;
touchedFields?: string[] | FieldNamesFn;
touched?: string[] | FieldNamesFn;
dirtyFields?: string[] | FieldNamesFn;
}
): void;
Expand Down
10 changes: 5 additions & 5 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export default <V extends FormValues = FormValues>({
values,
{
shouldValidate = validateOnChange,
touchedFields = [],
touched = [],
dirtyFields = [],
} = {}
) => {
Expand All @@ -590,14 +590,14 @@ export default <V extends FormValues = FormValues>({
setStateRef("values", values);
setNodesOrStateValue(values);

if (touchedFields.length)
if (touched.length)
setStateRef(
"touched",
setTrueValues(
stateRef.current.touched,
isFunction(touchedFields)
? touchedFields(getFieldNames())
: touchedFields
isFunction(touched)
? touched(getFieldNames())
: touched
)
);
if (dirtyFields.length)
Expand Down

0 comments on commit 92289f1

Please sign in to comment.