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

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

Comments

jrockowitz created an issue. See original summary.

jrockowitz’s picture

Title: Add Advanced Submission Limit Handler » Add Webform Options Limit Handler
Issue summary: View changes
jrockowitz’s picture

Issue summary: View changes
jrockowitz’s picture

Issue summary: View changes

  • 8237fbe committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler
    

  • 70169d9 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler
    

  • 5b74b57 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler
    

  • 8abe5ba committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Bug fixes and cleanup...

  • 6469b51 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Add unlimited message...

  • ca406cb committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Add summary.
    

  • 9af4fd5 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    

  • e76be03 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    

  • 24ca68d committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    

  • 55821b0 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    
  • c1223e8 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. API review and...

  • 99e0105 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...

  • d469fea committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...

  • 4372b03 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 7bc229c committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...

  • 577d774 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Improve limits
    

  • 7eacee5 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Add leave blank...

  • e369651 committed on 3076750-webform-options-limit
    Issue #3076750: Add Webform Options Limit Handler. Update description.
    

  • 24ca68d committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    
  • 4372b03 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 55821b0 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    
  • 577d774 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Improve limits
    
  • 5b74b57 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler
    
  • 6469b51 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add unlimited message...
  • 70169d9 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler
    
  • 7bc229c committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 7eacee5 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add leave blank...
  • 8237fbe committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler
    
  • 8abe5ba committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Bug fixes and cleanup...
  • 99e0105 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 9af4fd5 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    
  • c1223e8 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. API review and...
  • ca406cb committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add summary.
    
  • d469fea committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • e369651 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Update description.
    
  • e76be03 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    

  • b782b2e committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    

  • 52e82c0 committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

Attached patch has test coverage but I would like to update the UAT.

  • 34a94a0 committed on 8.x-5.x
    Revert "Issue #3076750: Add Webform Options Limit Handler. Add tests."...
  • d6eb00e committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
  • e46d2c5 committed on 8.x-5.x
    Revert "Issue #3076750: Add Webform Options Limit Handler. Add tests."...
  • ef8e83c committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
jrockowitz’s picture

So 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.

  • fbd0b9e committed on 8.x-5.x
    Issue #3076750: Add Webform Options Limit Handler. Fix broken tests.
    
jrockowitz’s picture

Issue summary: View changes

  • fcf5aa7 committed on 8.x-5.x
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Remove...

  • 24ca68d committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    
  • 4372b03 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 55821b0 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Fix default value.
    
  • 577d774 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Improve limits
    
  • 5b74b57 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler
    
  • 6469b51 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add unlimited message...
  • 70169d9 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler
    
  • 7bc229c committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 7eacee5 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add leave blank...
  • 8237fbe committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler
    
  • 8abe5ba committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Bug fixes and cleanup...
  • 99e0105 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • 9af4fd5 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    
  • c1223e8 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. API review and...
  • ca406cb committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add summary.
    
  • d469fea committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Build limit summary...
  • e369651 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Update description.
    
  • e76be03 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add validation.
    
  • 34a94a0 committed on 3076750-webform-options-limit-v02
    Revert "Issue #3076750: Add Webform Options Limit Handler. Add tests."...
  • 52e82c0 committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
  • 69927cb committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Create...
  • b782b2e committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
  • d6eb00e committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
  • e46d2c5 committed on 3076750-webform-options-limit-v02
    Revert "Issue #3076750: Add Webform Options Limit Handler. Add tests."...
  • ef8e83c committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Add tests.
    
  • fbd0b9e committed on 3076750-webform-options-limit-v02
    Issue #3076750: Add Webform Options Limit Handler. Fix broken tests.
    
  • fcf5aa7 committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Remove...
jrockowitz’s picture

StatusFileSize
new76.21 KB

I 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.

  • 37e45ae committed on 8.x-5.x
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Fix...

  • 37e45ae committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Fix...
  • 5b6698e committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Fix...
jrockowitz’s picture

StatusFileSize
new78.83 KB
Mile3’s picture

Thanks 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"
}
}

  • 1c04559 committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler.
    
jrockowitz’s picture

StatusFileSize
new78.77 KB

Please try the attached patch.

  • 8ad5a24 committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Add...
jrockowitz’s picture

This patch adds support for entity select, checkboxes, and radios.

Mile3’s picture

Works 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.

  • 28883ac committed on 3076750-webform-options-limit-v02
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler. Fix...
jrockowitz’s picture

StatusFileSize
new91.39 KB

Please try the attached patch.

Mile3’s picture

Works very well. I think we're in good shape here. LMK when you're ready to close this one out. Thanks Jacob.

  • jrockowitz authored 63def8c on 8.x-5.x
    Issue #3076750 by jrockowitz: Add Webform Options Limit Handler
    
jrockowitz’s picture

Status: Needs review » Fixed
jrockowitz’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Mile3’s picture

Perhaps 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.

jrockowitz’s picture

Per user option limits is a slightly different feature request. Please open a new ticket.

Germain Ch.’s picture

Hello,
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!

Mile3’s picture

Hi 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?