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

New feature: Allow empty value for select form controls, based on user setting. #3041

Merged
merged 2 commits into from Jan 19, 2022
Merged

New feature: Allow empty value for select form controls, based on user setting. #3041

merged 2 commits into from Jan 19, 2022

Conversation

vlad-ghita
Copy link
Contributor

Use case

  • have a required select field;
  • select field must not pre-select any option;
  • user must deliberately choose an option;

Current Bolt behaviour automatically selects first option if field is required.

Solution

Add a configuration setting called allow_empty which enables developer to force an empty option for select control, even when control is required.

allow_empty setting is available in following definitions:

  • select field
  • relations
  • taxonomies

Image below shows definitions with these settings:

required: true
allow_empty: true

sample_relations_and_taxonomies

Testing

Manually tested these combinations:

required allow_empty
none none
none true
none false
true none
true true
true false
false none
false true
false false

Further improvements

  • automatic validation. Given empty option is added automatically, Bolt can automatically validate select value and return an error.
  • unit test

@bobdenotter
Copy link
Member

Hi @vlad-ghita I'm going to review this PR. Thanks!

I've fixed a tiny CS issue directly in the PR. It's still complaining about a PHPStan error, but this is fixed upstream, already.

@bobdenotter bobdenotter merged commit 6c15cbc into bolt:master Jan 19, 2022
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