Skip to content

Commit 673536c

Browse files
committed
2 parents 1c2a469 + 2b0f66b commit 673536c

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rc-component/form",
3-
"version": "1.2.0",
3+
"version": "1.3.1",
44
"description": "React Form Component",
55
"typings": "es/index.d.ts",
66
"engines": {

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export type ValuedNotifyInfo = NotifyInfo & {
204204
};
205205

206206
export interface Callbacks<Values = any> {
207-
onValuesChange?: (changedValues: any, values: Values) => void;
207+
onValuesChange?: (changedValues: Partial<Values>, values: Values) => void;
208208
onFieldsChange?: (changedFields: FieldData[], allFields: FieldData[]) => void;
209209
onFinish?: (values: Values) => void;
210210
onFinishFailed?: (errorInfo: ValidateErrorEntity<Values>) => void;

src/useForm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ export class FormStore {
812812
value,
813813
errors: [],
814814
warnings: [],
815+
touched: true,
815816
},
816817
]);
817818
};

tests/index.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ describe('Form.Basic', () => {
885885
Array.from(container.querySelectorAll<HTMLInputElement>('input')).map(input => input?.value),
886886
).toEqual(['bamboo', 'little', 'light', 'nested']);
887887

888+
// Check initial touched state
889+
expect(formRef.current.isFieldTouched(['list', 1])).toBeFalsy();
890+
expect(formRef.current.isFieldTouched(['nest', 'target'])).toBeFalsy();
891+
888892
// Set
889893
act(() => {
890894
formRef.current.setFieldValue(['list', 1], 'tiny');
@@ -894,6 +898,15 @@ describe('Form.Basic', () => {
894898
expect(
895899
Array.from(container.querySelectorAll<HTMLInputElement>('input')).map(input => input?.value),
896900
).toEqual(['bamboo', 'tiny', 'light', 'match']);
901+
902+
// Check that setFieldValue DOES set touched to true
903+
// (setFieldValue internally calls setFields with touched: true)
904+
expect(formRef.current.isFieldTouched(['list', 1])).toBeTruthy();
905+
expect(formRef.current.isFieldTouched(['nest', 'target'])).toBeTruthy();
906+
907+
// Verify other fields remain untouched
908+
expect(formRef.current.isFieldTouched(['list', 0])).toBeFalsy();
909+
expect(formRef.current.isFieldTouched(['list', 2])).toBeFalsy();
897910
});
898911

899912
it('onMetaChange should only trigger when meta changed', () => {

0 commit comments

Comments
 (0)