Skip to content

Commit ec09706

Browse files
committed
Add shouldFocus option to setValue method
1 parent 34c3c2b commit ec09706

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/solid/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the library will be documented in this file.
44

5+
## vX.X.X (Month DD, YYYY)
6+
7+
- Add `shouldFocus` option to `setValue` method
8+
59
## v0.7.0 (November 08, 2022)
610

711
- Add `validateIfNecessary` util and refactor code

packages/solid/src/methods/setValue.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type ValueOptions = Partial<{
66
shouldTouched: boolean;
77
shouldDirty: boolean;
88
shouldValidate: boolean;
9+
shouldFocus: boolean;
910
}>;
1011

1112
/**
@@ -30,6 +31,7 @@ export function setValue<
3031
shouldTouched = true,
3132
shouldDirty = true,
3233
shouldValidate = true,
34+
shouldFocus = true,
3335
} = options;
3436

3537
// Ignores tracking of reactive dependencies
@@ -57,7 +59,7 @@ export function setValue<
5759
if (shouldValidate) {
5860
validateIfNecessary(form, name, {
5961
on: 'input',
60-
shouldFocus: true,
62+
shouldFocus,
6163
});
6264
}
6365
});

packages/website/src/routes/api/setValue.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ setValue(form, name, value, options);
2121
- `shouldTouched` <Property {...properties.shouldTouched} />
2222
- `shouldDirty` <Property {...properties.shouldDirty} />
2323
- `shouldValidate` <Property {...properties.shouldValidate} />
24+
- `shouldFocus` <Property {...properties.shouldFocus} />
2425

2526
### Explanation
2627

2728
By default, the field is set to touched and the dirty state is updated. If you don't want this, you can set `shouldTouched` and/or `shouldDirty` to `false`.
2829

2930
By default, the field is validated according to the rules defined in the `options` of <A href="/api/createForm">`createForm`</A>. To disable validation you can set `shouldValidate` to `false`.
3031

32+
By default, the field is focused when an error occurs during validation. To change this behavior you can set `shouldFocus` to `false`.
33+
3134
## Return
3235

3336
- `value` <Property {...properties.value} />
@@ -65,4 +68,8 @@ export const properties = {
6568
type: 'boolean',
6669
defaultValue: { type: 'boolean', value: true },
6770
},
71+
shouldFocus: {
72+
type: 'boolean',
73+
defaultValue: { type: 'boolean', value: true },
74+
},
6875
};

0 commit comments

Comments
 (0)