-
-
Notifications
You must be signed in to change notification settings - Fork 600
Closed
Labels
Description
Bug description
- Conditionally hidden fields still submit values, preventing use of
sometimes,required_if, etc. validation rules.
How to reproduce
- Add a conditionally hidden field with
sometimes|requiredvalidation.- handle: last_name field: type: text if: first_name: 'not empty' validate: - sometimes - required
- This field should only show if
first_nameis not empty, and should only validate asrequiredif visible / present in the request.
Versions
Statamic 3.2.29 Pro
Laravel 8.78.1
PHP 7.4.25
Additional details
- The issue here is that hidden field values are always submitted, despite whether or not they are visible, so rules like
sometimesandrequired_ifdon't work as expected in the CP.- This is already fixed for front-end form conditions in Frontend form field conditions ... #4949 👍
- We could port this fix to the CP publish forms by doing the following:
- Ensure we don't submit hidden field values in publish form payload in JS.
- Set
->setTrackMissingValues(true)on the submitted fields before adding request data for validation.$fields ->setTrackMissingValues(true) ->addValues($request->all()) ->validate()