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

Allow empty strings on select prompt #99

Merged
merged 2 commits into from
Oct 27, 2023

Conversation

jessarcher
Copy link
Member

The current required validation approach is a "one size fits all" in terms of what is considered invalid when a prompt is required.

For a text prompt, an empty string from the user shouldn't be accepted when the prompt is required. But with a select prompt, it's possible to pass an empty string key as one of the configured options (potentially as a marker for something), and it seems unreasonable that a configured option would cause a validation error by default.

This PR addresses this by allowing each prompt to configure what should be considered invalid when the prompt is required. For now, I don't see a need to configure this for every prompt, so I've kept the current values as the "default" set and just updated the SelectPrompt with an override.

It's still possible to add a custom validation handler to prevent a configured option from being selected if needed.

It was also pointed out in #98 that setting the $required value to an empty string would disable validation due to truthy check, so I've also tightened this up.

Fixes #98.

@taylorotwell taylorotwell merged commit e1379d8 into main Oct 27, 2023
6 checks passed
@taylorotwell taylorotwell deleted the allow-empty-string-keys-on-select branch October 27, 2023 13:54
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.

SelectPrompt $required is not allowed to be false
2 participants