Wrong validation of required integer fields with value of "0"

Created on 11 March 2025, about 1 month ago

Problem/Motivation

Conditional Fields does not validate integers the same way that Drupal does. An integer field with a value of 0 and being Required by this module returns an error indicating the field is required despite the fact that the field is not empty

Steps to reproduce

1. Add two fields on any entity, for example taxonomy:
field_one - number (integer), minimum value set to 0;
field_two - boolean;
2. Go to admin/structure/conditional_fields/taxonomy_term/{your_vocabulary}
Add condition: field_one is required if field_two checked.
3. Edit term: check field_two, set 0 to field_one, save.

Proposed resolution

Update validation in ConditionalFieldsFormHelper.php -> dependentValidate:
use
if (empty($input_state) && $input_state !== '0')
instead of
if (empty($input_state))

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024