Problem/Motivation
When a Webform Booking element is marked as required and has a visibility condition (e.g., visible only when another field has a specific value), the required validation is bypassed. Users can submit the form without selecting a day/time slot in the booking calendar.
Steps to reproduce
1. Create a webform with a select/radios field and a Booking element.
2. Mark the Booking element as required.
3. Add a visibility condition on the Booking element (e.g., visible when the select field equals a specific value).
4. Visit the form, select the triggering value so the booking element becomes visible.
5. Submit the form without selecting a slot in the booking calendar.
6. Expected: Validation error saying the booking field is required.
7. Actual: Form submits successfully without any error.
Note: When the Booking element is unconditionally required (no visibility condition), the validation works correctly.
Proposed resolution
Two changes to fix both issues:
1. **`src/Plugin/WebformElement/WebformBooking.php`** — Update `validateEmptySlot()` to check both `$element['#required']` and `$element['#_required']`, so conditional required (via visibility states) is respected.
2. **`src/Element/WebformBooking.php`** — Add a `setRequiredError()` static method. This is the hook that `WebformSubmissionConditionsValidator` calls (via `method_exists`) to let custom elements handle their own required validation. The method checks whether the `slot` value is actually empty and sets the appropriate form error.
Remaining tasks
Review and test.
User interface changes
None.
API changes
A new public static method `WebformBooking::setRequiredError()` is added to the Element class (`src/Element/WebformBooking.php`).
Data model changes
None.
Issue fork webform_booking-3591982
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
aren33k commentedCode changes were made, ready to be reviewed.
Comment #4
rfmarcelino commentedThank you @aren33k
Reproduced the issue and tested the patch.
Merged
Comment #5
aren33k commented@rfmarcelino thanks!
Comment #6
aren33k commented@rfmarcelino I’m setting the status to fixed.