Select list fields is not emptied with "Empty" Action

Created on 25 July 2024, 9 months ago

Problem/Motivation

When empty action is set on a select list dropdown field, it is not emptied. Instead, conditional_fields module attempts to set the dropdown to an empty string, i.e. value="" which is an illegal choice, instead of value='_none', the legal choice. Conditional Fields module is unable to select the correct empty_value for list fields, hence "_none" is not selected and the empty action does not happen, so it reverts back to the originally selected value and does not empty the field.

I tried using form_alter to supply an empty string to the #empty_value and removing the default empty_value "_none", I received an illegal choice error.

<select ... >
<option value="_none">- None -</option>
<option value="plane">Plane</option>
<option value="train">Train</option>
</select>

vs

<select ... >
<option value="">- None -</option>
<option value="plane">Plane</option>
<option value="train">Train</option>
</select>

Steps to reproduce

Add a checkbox and a select list field. Configure conditional_field to empty the list_field when the checkbox is checked.

I noticed that Core sets default/empty option values to "_none" on optional list (un-required) fields. If the #empty_value of the field were to be an empty string, i.e. value="", then conditional fields would empty it correctly but that is not Drupal Core provides for list fields. Core provides "_none". So for the empty state to successfully empty the select field, it needs to be able to set it the empty_value to "_none".

Setting the #empty_value to an empty string is not the same as setting it to '_none'. Since Core provides '_none', the select field is considered as having a value, so it's not an empty state.
I am looking for ideas or a possible solution to this.
Please share any insights on this issue. Thanks!

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jumoke

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

Comments & Activities

Production build 0.71.5 2024