Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently, it's not possible to enforce unique values for select components as it is with other components, such as email. For example, with the email component, it's possible to restrict submissions such that a single e-mail address can only be submitted once for a given webform. This issue proposes extending the select component to support the same functionality so that once a select option has been submitted, it is no longer available for future submissions.
Proposed resolution
- Add a 'Unique' checkbox as an option on the 'select' component's edit page
- Extend _webform_render_select() to run submissions through webform_validate_unique() if unique is selected for the component
- Extend _webform_render_select() to remove previously submitted options from the options array if unique is select for the component
- It will be possible to disable options instead of removing them once #1077532: Implement "Disabled"-functionality for "Select options" also is committed
- If no options remain after previously submitted options are removed, then the component is disabled and an empty option labeled, "No options available" is printed
Remaining tasks
Need to submit patch
User interface changes
'Unique' checkbox is added as an option for the 'select' component on the component's edit page.
API changes
None
Data model changes
None
Comments
Comment #2
Chris Burge CreditAttribution: Chris Burge commentedComment #3
Liam MorlandComment #4
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe two year old patch in #2 still applies cleanly to the latest 7.x-4.x-dev and would be great to see this patch committed.
Comment #5
aaldayel CreditAttribution: aaldayel commentedPatch in #2 works for me too.
Comment #6
Chris Burge CreditAttribution: Chris Burge commented@Chris Matthews, @aaldayel - Thanks for testing out this patch. Setting the issue status to RTBC will help move it along.
Comment #7
Liam MorlandThanks for the patch.
Please use a Boolean instead of integer for the value. Add @todo next to the reference to #1077532: Implement "Disabled"-functionality for "Select options" also.
What happens if there are no options left and the field is mandatory?
This should have tests.