Filter exposes unlabelled option and error for NULL values in database

Created on 23 July 2024, 6 months ago

I have encountered an issue with the bef_select module in Drupal 10. When the field used for the bef_select filter has NULL values in the database, the select filter presents an option without a label on the form. Additionally, when the form is displayed, this unlabelled option is automatically marked with a red error border. Upon submission, an error message is shown: "The submitted value %choice in the %name element is not allowed."

I believe that the bef_select filter should be capable of detecting NULL values and create a specific option to handle this case, perhaps labelled as "No value" or similar. This would improve the user experience by providing a more accurate representation of the data in the select filter and avoid confusion with unlabelled options and error messages.

Meanwhile, as a temporary workaround, I suggest transforming NULL values into a default value - such as 'N/A' or 'Undefined' - before the form is populated. This transformation could occur at the query level or via a preprocessing function, ensuring that the select filter only exposes valid and labelled choices.

Steps to reproduce:
1. Have a field in the database that is used by bef_select with some NULL values.
2. Display the filter form on a page.
3. Observe the unlabelled option and error mark on the select filter.

Expected result:
No option should be shown for NULL values, or a specific "No value" option should be created and selected without causing an error.

Actual result:
An unlabelled option is displayed, and upon form display, it is marked with a red error border, leading to the error message mentioned above when submitting.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇪🇸Spain psf_ Huelva

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024