Skip to content

[6.x] Fix required validation on empty code fields - #14918

Merged
jasonvarga merged 1 commit into
6.xfrom
required-code-field
Jul 2, 2026
Merged

[6.x] Fix required validation on empty code fields#14918
jasonvarga merged 1 commit into
6.xfrom
required-code-field

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where setting a code fieldtype to required had no effect — an empty field would pass validation and the entry would save.

This was happening because the code fieldtype submits an object ({ code: null, mode: '...' }) rather than a scalar. Since that object is a non-empty array, Laravel's required rule considered it present and passed.

This PR fixes it by adding a preProcessValidatable method to the fieldtype, which unwraps the object so validation rules run against the code string itself. When the field is empty, required now correctly fails.

Fixes #14907

Validate against the code string rather than the wrapping object so
`required` fails when a code field is left empty.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 43dcac1 into 6.x Jul 2, 2026
22 checks passed
@jasonvarga
jasonvarga deleted the required-code-field branch July 2, 2026 16:20
duncanmcclean added a commit to mefenlon/cookie-notice that referenced this pull request Jul 8, 2026
The Code fieldtype now passes the plain code string to validation
rules, rather than an array (statamic/cms#14918).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty code fieldtype passes required validation

2 participants