"This value should be of the correct primitive type" error when field has no value

Created on 18 March 2014, almost 11 years ago
Updated 25 April 2024, 8 months ago

Problem/Motivation

I have a Field API field and I have attached it to an entity. This field has multiple fields in it. When I submit the form without all fields filled I get the "This value should be of the correct primitive type." error.

Is this a bug or am I doing something wrong? I was having trouble with serialized field for storing metadata but I've been able to get around it by setting it to computed field. But I cannot do that in this case.

Steps to reproduce

TBA

Proposed resolution

TBA

Remaining tasks

Issue Summary update

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Following discussion thread in #52, and being broadly in the same scenario (custom entity reference field type and a widget that extends EntityReferenceAutocompleteWidget), for me the validation error could be avoided by making $form_state->setValueForElement($element, ['target_id' => null]) when the field is submitted empty, in the validate method.

Production build 0.71.5 2024