Problem/Motivation
The Webform module includes general submission limit by webform, source entity, and user. There are use cases where an individual select menu (a.k.a an options element) might want to limit submission per option. An example of this feature could be a booking form where a maximum of two people can select a certain time slot.
Proposed resolution
Add a Webform Options Limit handler which allows submission limits to be defined for each option or even image.
Remaining tasks
- Create webform_options_limit.module
- Create a OptionsLimitWebformHandler
- Add options limit example to event registration demo
- Create test webform
- Write tests
- Create change record
User Acceptance Test
- Enable the Webform Options Limit module (/admin/modules)
- Create a new Webform with select menu (/admin/structure/webform)
- Add an 'Options Limit' handle to the webform (/admin/structure/webform/manage/WEBFORM/handlers)
- Set options specific and default limits
- Set custom messages
- Test webform options limits and custom message.
Notes
- Option submission limit can be applied to webform or source entity.
- Each option or image can have submission limit.
- Displaying option submission limits can be optional
- Limit can have custom singular or plural label and message. (i.e. "1 slot remaining", "1 slots remaining" or "no more slots available")
- When an option submission limit is reached, options can be disabled or removed.
- Option submission limits can be summarized below the element.
References
- #3076687: Table Picker / Flag Field Custom Development Offer
- #3046452: Limit Select Fields Choices Based On Previous Submissions
- Webform Select Limit
User interface changes
No changes to the Webform UI just a new OptionsLimitWebformHandler
API changes
OptionsLimitWebformHandler should be able to encapsulate the new API without a dedicated service.
Data model changes
None
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | 3076750-42.patch | 91.39 KB | jrockowitz |
| #37 | 3076750-37.patch | 78.77 KB | jrockowitz |
| #34 | 3076750-34.patch | 78.83 KB | jrockowitz |
| #31 | 3076750-31.patch | 76.21 KB | jrockowitz |
| #24 | 3076750-24.patch | 0 bytes | jrockowitz |
Comments
Comment #2
jrockowitz commentedComment #3
jrockowitz commentedComment #4
jrockowitz commentedComment #24
jrockowitz commentedAttached patch has test coverage but I would like to update the UAT.
Comment #26
jrockowitz commentedSo it turns out that I accidentally merged the '3076750-webform-options-limit' branch into 8.x-5.x. The code is fairly stable and I don't have a few hours to revert all the commit so I am going to roll with this mistake and you can checkout the latest dev release to review this feature.
Comment #28
jrockowitz commentedComment #31
jrockowitz commentedI felt that the prematurely release of this submodule was bad idea. So I removed the webform_options_limit.module from the 8.x-5.x branch and attached is a dedicated patch with the webform_options_limit.module. I did leave the related minor tweaks to webform core in the 8.x-5.x branch.
Sorry for the confusion.
Please review the attached patch. Here is the draft change record.
Comment #34
jrockowitz commentedComment #35
Mile3 commentedThanks Jacob.
I'm unable to apply patch using composer:
Gathering patches for dependencies. This might take a minute.
- Installing drupal/webform (dev-5.x 1854ac6): Cloning 1854ac64ab
- Applying patches for drupal/webform
https://www.drupal.org/files/issues/2019-09-12/3076750-34.patch (Options Limit)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2019-09-12/3076750-34.patch
See composer.json below:
"extra": {
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/contrib/{$name}": [
"type:drupal-drush"
]
},
"patches": {
"drupal/webform": {
"Options Limit": "https://www.drupal.org/files/issues/2019-09-12/3076750-34.patch"
}
}
Comment #37
jrockowitz commentedPlease try the attached patch.
Comment #39
jrockowitz commentedThis patch adds support for entity select, checkboxes, and radios.
Comment #40
Mile3 commentedWorks great. Thank you.
One concern remaining- when I use the field type "Entity Checkboxes", then select "Element Options" > "Options Display" > "Buttons", they still show as checkboxes, not buttons.
Comment #42
jrockowitz commentedPlease try the attached patch.
Comment #43
Mile3 commentedWorks very well. I think we're in good shape here. LMK when you're ready to close this one out. Thanks Jacob.
Comment #45
jrockowitz commentedComment #46
jrockowitz commentedComment #48
Mile3 commentedPerhaps this is a new request, but I realized I will also need to limit options per user. That is, on a form where a user can create multiple submissions, they should only be allowed to select an option once, but other users on the same form should also be able to submit the option once themselves. Hope that makes sense.
Comment #49
jrockowitz commentedPer user option limits is a slightly different feature request. Please open a new ticket.
Comment #50
Germain Ch. commentedHello,
Your module is exactly what I'm looking for, thank you!
On the other hand, I installed and configured it, and I don't have the impression that it is active (I activated the handler in the webform).
I have clearly defined the boundaries by field.
I have the summary of the results (/results/options-limit) by options with the filling gauges (which tells me that I have exceeded the authorized limits).
But I can validate the form as many times as I want, I don't have a message, the options are not disabled.
I don't have the messages of the remaining number.
Webform version: 8.x-5.4
Drupal version: 8.7.7
Thank you for your help!
Comment #51
Mile3 commentedHi Germain,
I'll be glad to help you.
First of all, try using 5.x-dev instead of 5.4. See if that helps.
If that doesn't work, can you share your webform YAML source code so I can see what you're trying to do?