feature: add Minimum Length option for text fields - #7605
Conversation
- Add text, paragraph, wysiwyg min_length field options (default 0 = no minimum) - Reject non-empty values shorter than the minimum on save with a clear error - Enforce server-side only; leaves blank values to the existing required check Gives authors a way to require a certain amount of text in a field, matching the existing Maximum Length option. Min length cannot be enforced by truncation like max length, so it validates instead and blocks the save. Fixes pods-framework#7413
|
AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me. |
… errors .phpcs.xml enables WordPress.WP.I18n, which requires a translators comment on any sprintf( __( ... ) ) carrying placeholders. Every other translated error string in classes/fields/ has one (phone.php:177, website.php:233, email.php:150, link.php:245, pick.php:1408), so these three would have failed phpcs. Placeholders are numbered at the same time so translators can reorder the label and the count, which several languages need. Refs pods-framework#7413
sc0ttkclark
left a comment
There was a problem hiding this comment.
This should probably abstract something the min length logic into a Field_Validation trait, maybe in src/Pods/Data/Traits/Field_Validation.php
Also add tests for the fields in tests/codeception/wpunit/Pods/Field or add a test for the trait itself
- Move duplicated min-length validation into src/Pods/Data/Traits/Field_Validation.php, used by Text, Paragraph, and WYSIWYG fields - Add tests for min-length validation across all three field types Addresses review feedback from @sc0ttkclark. Refs pods-framework#7605
|
Hi @sc0ttkclark, thanks for the review. I moved the min length check into a trait at I also added tests for all three fields in Changes are in commit 648b20b. Ready for another look. |
Description
Adds a Minimum Length option to the Plain Text, Plain Paragraph Text, and WYSIWYG field types. It mirrors the existing Maximum Length option, but enforces a floor instead of a ceiling: a non-empty value shorter than the configured minimum is rejected on save with a clear error.
Maximum Length works by silently truncating the value, which is not possible for a minimum. So instead the new option validates in each field's
validate()method and blocks the save when the cleaned value is shorter than the minimum. Blank values are left to the existing required-field check, so a minimum is never enforced on an empty field.Related GitHub issue(s)
Fixes #7413
Testing instructions
10). Save the field.Screenshots / screencast
None. This is an admin option plus server-side validation, with no visible front-end change beyond the existing error messaging.
Changelog text for these changes
Enhancement: Text, Paragraph, and WYSIWYG fields now support a Minimum Length option that requires non-empty values to meet a character floor on save. #7413 (@faisalahammad)
PR checklist