Required fields should stay required

Created on 4 September 2024, 12 months ago
Updated 28 July 2025, about 1 month ago

Problem/Motivation

If a field is required, setting it to use the Read Only form widget should not un-require it.

Steps to reproduce

Configure a field to be required in the field settings, no default value. Go to form display and set that field to use the Read only widget. Create content with no value passed in (so no entity reference prepopulate for example). It will save without validation error preventing this.

Proposed resolution

Probably some people are relying on the current behavior. Could it be made configurable on the widget?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

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

Merge Requests

Comments & Activities

  • Issue created by @mlncn
  • First commit to issue fork.
  • Merge request !7Add "Error Validation" setting. β†’ (Merged) created by lolgm
  • Pipeline finished with Failed
    about 1 month ago
    Total: 284s
    #558557
  • πŸ‡΅πŸ‡ΉPortugal lolgm

    The MR !7 introduces a new configuration option for the Read only widget, allowing users to decide whether required field validation should be enforced.

    To preserve backward compatibility with the current module behavior, this option defaults to FALSE.

    At the moment, this MR does not include tests for the new functionality, as the existing tests are currently failing. From what I can tell, the failures seem related to recent changes in Drupal core, and not caused by this patch.

    I’ve confirmed locally that the tests fail on Core 11, but pass on Core 10.

    Can someone confirm whether these failures also occur on the latest Core 11 version without this MR applied?

  • πŸ‡¦πŸ‡ΊAustralia thtas

    Oh dear yes the tests are indeed broken. I've created a new 2.x dev branch and will try and make things green again.

    re: this issue

    Yes it seems ok to me.

    What sort of scenario would you need this option for?

  • πŸ‡΅πŸ‡ΉPortugal lolgm

    Thank you for the feedback, @thtas.

    My use case involves:

    • Two content types: A and B.
    • A required entity reference field on node type B, pointing to a node type A, using the Read only widget.
    • The reference is auto-populated via query parameters when accessing the form at /node/add/b, using the Entity Prepopulate (epp) module.

    In this scenario, I need the required field validation to be enforced, because it's critical that the reference to the related node is always present when creating content of type B.

    Without validation, users could create content without the necessary reference β€” for example, by editing or removing the query parameter β€” which would break data integrity in my case.

  • πŸ‡¦πŸ‡ΊAustralia thtas

    Thank you for the contribution! This is merged

  • πŸ‡΅πŸ‡ΉPortugal lolgm

    @thtas Thank you for your follow-up. Would it be possible to also include me in the issue credits?

  • πŸ‡¦πŸ‡ΊAustralia thtas
  • πŸ‡¦πŸ‡ΊAustralia thtas
  • πŸ‡΅πŸ‡ΉPortugal lolgm

    @thtas Thank you :)

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024