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

Issue #4036: Allow for an empty option in select fields via schema pr… #4037

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from

Conversation

stefan-korn
Copy link
Contributor

@stefan-korn stefan-korn commented Oct 6, 2023

fixes #4036

  • Test coverage exists
  • Documentation exists

QA Steps

  • create or edit a dataset with an optional list (enum) field (like accrualPeriodicity) and note that there will be an empty option beside the real values in the select dialog
  • if you save with the empty option the value should not exist in the json stored

@dafeder
Copy link
Member

dafeder commented Oct 6, 2023

See my comment on the issue @stefan-korn, I think the proper behavior here is just to add an empty option in the select for any enum that is not required, and make sure the JSON that is produced does not contain the property.

@@ -77,6 +77,9 @@ public function handleStringElement($definition, $data, $object_schema = FALSE)
// Add options if element type is select.
if ($element['#type'] === 'select') {
$element['#options'] = $this->getSelectOptions($property);
if ($property->empty_value) {
$element['#empty_value'] = '';
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we're going a different direction anyway, but not sure where $property->empty_value is supposed to be getting set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I supposed it to be set in the schema .json file, just like "type", "format", etc. But yes now we are going a different and better way.

@dafeder
Copy link
Member

dafeder commented Oct 6, 2023

@stefan-korn do you feel up to updating the tests? I think you should be able to see the circleCI results and that the tests are all broken now... fairly trivial to update them to expect this and possibly to confirm the right result for both required and non-required fields, but if you're not familiar with PHPUnit let me know and we can help with that part.

@stefan-korn
Copy link
Contributor Author

I fixed the tests. The html output itself is not checked I suppose?

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.

Allow for an empty option in select fields via schema property
2 participants