[#3574404] Enforce non-empty values for required string fields in JSON Editor forms
Summary
Adds client-side validation that rejects empty or whitespace-only values for required string fields in JSON Editor forms. Previously, the required keyword only checked property presence, allowing empty strings to pass silently.
Changes
Custom validator (js/patternkit.jsoneditor.js)
- Validates required string fields produce "Value required" errors when empty
- Idempotent registration via flag to prevent duplicates across
attach()cycles
Media field error display (patternkit_media_library/.../media_library.js)
- Overrides
showValidationErrors()inDrupalMediaEditor— the parentAbstractEditorhas a no-op implementation, so errors were silently ignored
Form submission gates (js/patternkit.jsoneditor.js)
- Non-AJAX:
onSubmit()blocks submission and shows inline errors - AJAX:
validateBeforeAjaxSubmit()intercepts submit, resets AJAX state on failure so the button remains usable
AJAX wrapper rework (js/patternkit.jsoneditor.js)
- Replaced
hasOwnPropertyguards with explicit wrap-once flags - Resolved stale closure references — wrappers now resolve the active editor via
window.patternkitEditorat call time - Added null-safety for previous handler delegation
Testing
- Open Layout Builder → add Patternkit block with required string field
- Leave field empty → inline "Value required" error appears
- Click save → submission blocked, error visible
- Fill in field → error clears, save succeeds
- Verify media fields also show inline errors when required and empty
- Verify submit button stays enabled after validation failure (AJAX)
Closes #3574404.