Skip to content
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

Handle empty strings in JSON form #467

Merged
merged 1 commit into from Dec 21, 2023
Merged

Handle empty strings in JSON form #467

merged 1 commit into from Dec 21, 2023

Conversation

jbeisen
Copy link
Collaborator

@jbeisen jbeisen commented Dec 20, 2023

In the StringWidget component, if the string is empty then reset the field to undefined. This prevents validation false positives.

Also use the JSON schema 'dependentRequired' keyword in the Confluent schema, and surface object-level formik errors.

image

const onChangeWrapper = (e: React.ChangeEvent<any>) => {
onChange(e);

if (resetField && e.target.value == '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be before the parent onchange? For the connection page, we rely on onchange to synchronize the current state for validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue that since we want to set the value to undefined, we need to do that after onChange sets it to the empty string.

@jbeisen jbeisen force-pushed the json-form-empty-string branch 2 times, most recently from 74812d6 to ab6c543 Compare December 21, 2023 00:14
@@ -659,7 +669,7 @@ export function FormInner({
// @ts-ignore
onChange({ target: { name: path, value: {} } });
}
}, [schema]);
}, []);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwylde This should make it add the empty object on only the first render

In the StringWidget component, if the string is empty then reset the
field to undefined. This prevents validation false positives.

Also use the JSON schema 'dependentRequired' keyword in the Confluent
schema, and surface object-level formik errors.
@jbeisen jbeisen merged commit 0eb9d9e into master Dec 21, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants