Skip to content

Empty code fieldtype passes required validation #14907

Description

@daun

Bug description

Setting a code field to required has no effect. An empty field passes validation and allows saving the entry.

The payload sent from the fieldtype is an object, with the actual code value in a nested key. Submitting an empty field produces an object like this, which passes validation:

{ code: null, mode: 'application/ld+json'}

Ideally the code fieldtype could only send the object if a value is present, and plain null if not.

How to reproduce

Add a required code field to an entry blueprint.

  -
    handle: json_ld
    field:
      type: code
      mode: 'application/ld+json'
      validate:
        - required

Create an entry and submit with the code field empty.

Logs

Environment

Environment
Laravel Version: 13.17.0
PHP Version: 8.4.20
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: Europe/Vienna
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / daily
Mail: log
Queue: database
Session: file

Storage
public/storage: NOT LINKED

Statamic
Addons: 11
License Key: Not set
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 6.23.0 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions