InvalidComponentException: [disabled] NULL value found, but a boolean or an object is required. (radiocheckbox)

Created on 23 April 2024, 8 months ago
Updated 8 May 2024, 8 months ago

Problem/Motivation

In Radix 6.0.x (15a8615) the error:

Drupal\sdc\Exception\InvalidComponentException: [disabled] NULL value found, but a boolean or an object is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types. in Drupal\sdc\Component\ComponentValidator->validateProps() (line 205 of core/modules/sdc/src/Component/ComponentValidator.php).

Is triggered whenever the radio or checkbox elements are iterated over with no explicit value set for 'disabled' property.

Steps to reproduce

I imagine many things could trigger this, for my case it was a default Drupal commerce page (cart).

Install current dev version on D10.2.5 with Drupal Commerce 2.x
A number of pages then throw this error, the most prevalent being /cart (with any product in the basket).

Proposed resolution

The problem stems from the schema of the radiocheckbox element (radix/components/form-element--radiocheckbox/form-element--radiocheckbox.component.yml) not allowing null as a valid type.

The fix is two fold. In the Schema file:

Change:

disabled:
      type: boolean
      description: True if the element is disabled.

To:

disabled:
      type: ['boolean', 'null']
      description: True if the element is disabled, null if not specified.

then in the associated twig file, set a default for 'disabled' IF its not set.

{% set disabled = disabled|default(false) %}

{%
  set form_element_radiocheckbox_classes = [
    'js-form-item',
    'form-item',
    'form-check',
    'form-type-' ~ type|clean_class,
    'js-form-type-' ~ type|clean_class,
    'form-item-' ~ name|clean_class,
    'js-form-item-' ~ name|clean_class,
    title_display not in ['after', 'before'] ? 'form-no-label',
    disabled ? 'form-disabled',
    errors is not empty ? 'form-item--error',
  ]|merge(form_element__radiocheckbox_utility_classes ?: [])
%}

Merge request to follow.

🐛 Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

🇬🇧United Kingdom martin@manarock.co.uk

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