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

Trim descriptions, so whitespace-only descriptions don't get passed through #2516

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

charliepark
Copy link
Contributor

For discussion …

This PR fixes an edge case with DescriptionFields. Currently, they can be created with an empty space (or some other combination of whitespace) as the only text in the description. This PR updates the DescriptionField, so that when it is blurred, the value is trimmed.

I like this approach, as it keeps the change scoped to the DescriptionField component, whereas if we handled it at the form layer, we'd need to add a function in each place in the app where we use the DescriptionField. This way, it's handled within the one file. That being said, forcing an update to props.control._formValues.description feels off.

If we move forward with it …
Closes #2515

Copy link

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Oct 23, 2024 0:36am

@charliepark charliepark changed the title Trim descriptions Trim descriptions, so whitespace-only descriptions don't get passed through Oct 23, 2024
@benjaminleonard
Copy link
Contributor

I imagine it's a bit more work, but can we perhaps address this (oxidecomputer/omicron#4929) and set it to undefined if it's just whitespace.

const trimmedDescription = event.target.value.trim()
event.target.value = trimmedDescription
props.control._formValues.description = trimmedDescription
}}
Copy link
Collaborator

@david-crespo david-crespo Oct 28, 2024

Choose a reason for hiding this comment

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

I think blur is too specific of a place for this — shouldn't transform work? Or I guess that prevents you from ever typing whitespace. I'm thinking we should just not do this if this is the only way to do it. Ideally it would happen at submit time (which we might already be doing manually in a few paces), but I don't know of a way to wire this up at field level to happen on submit, which is at form level.

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.

make sure descriptions can't consist of only whitespace
3 participants