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 for an empty option in select fields via schema property #4036

Open
stefan-korn opened this issue Oct 6, 2023 · 6 comments · May be fixed by #4037
Open

Allow for an empty option in select fields via schema property #4036

stefan-korn opened this issue Oct 6, 2023 · 6 comments · May be fixed by #4037
Assignees

Comments

@stefan-korn
Copy link
Contributor

stefan-korn commented Oct 6, 2023

User Story

Currently you can not make use of the #empty_value property of the Drupal Select form element if using the basic select widget with the json_form_widget for a schema field.

You can use the select_other type for the list widget, but then you get the empty option and the other option.

There maybe cases where you only want the empty option but not allow the other option, i. e. an optional list field.

I propose to use a schema property on the dataset field to indicate this. Why not just name this "empty_value" and if this is set to true the #empty_value property will be used on the select form element.

One could maybe just inject an empty value in the "enum" property of the schema field, but this seems kind of "dirty".

Acceptance Criteria

@github-actions github-actions bot added this to Incoming/Triage in DKAN 2 Issue Triage Oct 6, 2023
@dafeder
Copy link
Member

dafeder commented Oct 6, 2023

So, in this scenario, what do you want the submitted JSON to look like? An empty array, or the property should not exist at all?

stefan-korn added a commit to stefan-korn/dkan that referenced this issue Oct 6, 2023
@stefan-korn
Copy link
Contributor Author

The property should not exist at all.
An optional value, you can select one from the list or select "None" and then it is empty.

@dafeder
Copy link
Member

dafeder commented Oct 6, 2023

We are trying to reproduce the behavior of react-jsonschema-form as much as possible, and it looks like there an enum field that is optional should always have an empty element in the select, which translates to no property in the JSON. We should make json_form_widget work the same way.

@stefan-korn
Copy link
Contributor Author

stefan-korn commented Oct 6, 2023

Okay, then we could just use
if (!$this->checkIfRequired($field_name, $element_schema)) {
instead of
if ($property->empty_value) {
?
(see PR #4037)

@dafeder
Copy link
Member

dafeder commented Oct 6, 2023

I think so! Does it produce the expected result?

stefan-korn added a commit to stefan-korn/dkan that referenced this issue Oct 6, 2023
@stefan-korn
Copy link
Contributor Author

Yes, no value is saved in the JSON if the empty option is chosen. Updated the PR.

stefan-korn added a commit to stefan-korn/dkan that referenced this issue Oct 7, 2023
stefan-korn added a commit to stefan-korn/dkan that referenced this issue Oct 7, 2023
@dafeder dafeder self-assigned this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
DKAN 2 Issue Triage
  
Incoming/Triage
Development

Successfully merging a pull request may close this issue.

2 participants