Schema validation triggers even if the field is not required and is empty

Created on 27 June 2024, 8 months ago
Updated 17 October 2024, 4 months ago

Problem/Motivation

If the json_editor widget is configured and set to validate JSON against a provided schema, the validation will trigger even if the field is defined as optional and is empty.

Steps to reproduce

  1. Enable the modules json_field and json_field_widget.
  2. Add a field of type to json_native to any content type. Make sure the field is optional (not required).
  3. Set the widget json_editor for the field created above. Make sure the input will be validated against a Json schema
  4. Attempt to save any node while leaving the json field completely empty
  5. Validation will trigger and will not let users save the form.

Proposed resolution

Address this issue from the Drupal\json_field_widget\Plugin\Field\FieldWidget::validateJsonData() static method since it is there where the validation happens.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡΄Colombia ibustos BogotΓ‘ D.C.

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