-
Notifications
You must be signed in to change notification settings - Fork 303
fix: ensure onChange reports modified=true for file components #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,7 @@ export type FormOptions = FormClass['options'] & { | |||||||||||||||||||||||||
| export type FormType = PartialExcept<CoreFormType, 'components'>; | ||||||||||||||||||||||||||
| export type FormSource = string | FormType; | ||||||||||||||||||||||||||
| interface FormConstructor { | ||||||||||||||||||||||||||
| new ( | ||||||||||||||||||||||||||
| new( | ||||||||||||||||||||||||||
| element: HTMLElement, | ||||||||||||||||||||||||||
| formSource: FormSource, | ||||||||||||||||||||||||||
| options: FormOptions, | ||||||||||||||||||||||||||
|
|
@@ -136,12 +136,20 @@ const onAnyEvent = ( | |||||||||||||||||||||||||
| handlers.onCancelComponent(outputArgs[0]); | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| case 'onChange': | ||||||||||||||||||||||||||
| if (handlers.onChange) | ||||||||||||||||||||||||||
| if (handlers.onChange) { | ||||||||||||||||||||||||||
| let modified = outputArgs[2]; | ||||||||||||||||||||||||||
| const flags = outputArgs[1]; | ||||||||||||||||||||||||||
| // Fixed: Check if the change is from a file component and ensure modified is true | ||||||||||||||||||||||||||
| // See https://github.com/formio/react/issues/632 | ||||||||||||||||||||||||||
| if (!modified && flags?.changed?.instance?.type === 'file') { | ||||||||||||||||||||||||||
|
Comment on lines
+142
to
+144
|
||||||||||||||||||||||||||
| // Fixed: Check if the change is from a file component and ensure modified is true | |
| // See https://github.com/formio/react/issues/632 | |
| if (!modified && flags?.changed?.instance?.type === 'file') { | |
| // Fixed: Check if the change is from a file-like component and ensure modified is true | |
| // See https://github.com/formio/react/issues/632 | |
| const changedInstance = flags?.changed?.instance as { type?: string } | undefined; | |
| const fileLikeComponentTypes = ['file', 'signature']; | |
| if ( | |
| !modified && | |
| changedInstance?.type && | |
| fileLikeComponentTypes.includes(changedInstance.type) | |
| ) { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
|
|
||||||
| import { render, screen, waitFor } from '@testing-library/react'; | ||||||
| import '@testing-library/jest-dom'; | ||||||
| import { Form } from '../Form'; | ||||||
|
|
||||||
| const fileForm = { | ||||||
| display: 'form' as const, | ||||||
| components: [ | ||||||
| { | ||||||
| label: 'Upload File', | ||||||
| key: 'file', | ||||||
| type: 'file', | ||||||
| input: true, | ||||||
| storage: 'base64', | ||||||
| }, | ||||||
| ], | ||||||
| }; | ||||||
|
|
||||||
| test('onChange should report modified=true when file is changed', async () => { | ||||||
| const handleChange = jest.fn((value, flags, modified) => { | ||||||
| // console.log('onChange called', { value, flags, modified }); | ||||||
|
||||||
| // console.log('onChange called', { value, flags, modified }); |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "Currently reproduces modified=false" is outdated after the fix has been applied. This comment implies the bug is still present, which is misleading. It should be updated or removed to reflect the current state where the fix ensures modified=true is correctly set.
| // Trigger change. Currently reproduces modified=false. | |
| // Trigger change; this previously reproduced modified=false before the fix. |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The console.log statement should be removed from production test code. Debug logging statements should not be committed in test files as they clutter the test output and provide no value in CI/CD environments.
| console.log('File Change Args:', { modified: args[2] }); |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "This should PASS after the fix" is outdated. Since the fix is already applied in this PR, the comment should state that this test verifies the fix works correctly, not that it will pass after a future fix.
| // This should PASS after the fix | |
| // This test verifies that the fix correctly reports modified=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be an unintentional formatting change where a space was removed between "new" and the opening parenthesis. The original format "new (" is more consistent with typical TypeScript/JavaScript style guides. This change should be reverted unless there's a specific style guide being followed that requires no space.