Problem/Motivation
When a Patternkit JSON Schema string field is both listed in required at the parent object level and declares minLength: 1 on the property, the JSON Editor form displays two identical "Value required." error messages under the same field when the field is left empty.
The text field in the patternkit_example module's example pattern already reproduces this exactly. It is required and declares minLength: 1.
The duplication happens because two independent validators both emit the error_notempty message for the same field path:
- The JSON Editor built-in
minLengthvalidator: whenminLength: 1is set and the value is"", it emitserror_notemptyat the field path withproperty: 'minLength'. - The Patternkit custom
patternkitRequiredStringValidatorinjs/patternkit.jsoneditor.js: it iteratesschema.required, finds the empty string field, and emitserror_notemptyat the same path withproperty: 'required'.
JSON Editor's _removeDuplicateErrors deduplicates on the triple (message, path, property). Because the two errors have different property values ('minLength' vs 'required'), the deduplication does not suppress the second message.
Steps to reproduce
- Enable
patternkit_example. - Place a Patternkit block using the Example pattern (
@patternkit/atoms/example/src/example) on any layout. - Open the block editor.
- Clear the Text field so it is empty.
- Click Update.
- Observe two "Value required." messages appear under the Text * field label.
Expected: One "Value required." message.
Proposed resolution
Add a guard condition inside the custom patternkitRequiredStringValidator loop in js/patternkit.jsoneditor.js. When a required string field's schema declares minLength as a number >= 1, the custom validator skips emitting error_notempty. The built-in minLength validator already emits it for this case.
The change is 10 lines, inline in the existing forEach callback. No new files or abstractions are introduced.
Behavior after fix:
- Required field +
minLength: 1+ empty value: one "Value required." (from the built-inminLengthvalidator only) - Required field + no
minLength+ empty value: one "Value required." (from the custom validator, unchanged) - Required field +
minLength >= 2+ empty value: one message from the built-in validator; custom validator skips - Non-empty value: no error (unchanged)
Remaining tasks
- Review and test the merge request.
- CI validation.
User interface changes
The inline validation display in Patternkit block editor forms changes from two "Value required." messages to one when a required string field also declares minLength: 1. The patternkit_example Example pattern's Text field is affected and can be used to verify the fix.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
Patternkit no longer displays a duplicate "Value required." validation message when a JSON Schema string field is both listed in required and declares minLength: 1. The patternkit_example Example pattern's Text field demonstrates the corrected behavior. Pattern authors do not need to change their schemas.
Issue fork patternkit-3593600
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
sluceroComment #4
sluceroReviewed and approved internally at Red Hat. Ready for merge for inclusion in the 9.1.3 release.
Comment #6
sluceroMerged for inclusion in the 9.1.3 release.
See #3542304: Patternkit 9.1.3 Release Plan.