Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ export class FormStore {
value,
errors: [],
warnings: [],
touched: true,
},
]);
};
Expand Down
13 changes: 13 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ describe('Form.Basic', () => {
Array.from(container.querySelectorAll<HTMLInputElement>('input')).map(input => input?.value),
).toEqual(['bamboo', 'little', 'light', 'nested']);

// Check initial touched state
expect(formRef.current.isFieldTouched(['list', 1])).toBeFalsy();
expect(formRef.current.isFieldTouched(['nest', 'target'])).toBeFalsy();

// Set
act(() => {
formRef.current.setFieldValue(['list', 1], 'tiny');
Expand All @@ -894,6 +898,15 @@ describe('Form.Basic', () => {
expect(
Array.from(container.querySelectorAll<HTMLInputElement>('input')).map(input => input?.value),
).toEqual(['bamboo', 'tiny', 'light', 'match']);

// Check that setFieldValue DOES set touched to true
// (setFieldValue internally calls setFields with touched: true)
expect(formRef.current.isFieldTouched(['list', 1])).toBeTruthy();
expect(formRef.current.isFieldTouched(['nest', 'target'])).toBeTruthy();

// Verify other fields remain untouched
expect(formRef.current.isFieldTouched(['list', 0])).toBeFalsy();
expect(formRef.current.isFieldTouched(['list', 2])).toBeFalsy();
});

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