Problem/Motivation
I discovered a bug with the Webform Options Limit [EXPERIMENTAL] sub module. It's possible to add the limit options handler to tableselect element, but the module is not able to append the messages to the label.
To replicate:
- Create webform with "Table select" element.
- Add a "Options Limit" handler and set limits to the elements.
- View the form, no information about remaining options are printed.
Proposed resolution
I'm not sure what is the best solution, but I made it work locally by doing this:
protected function alterOptionsElementLabels(array &$options, array $limits, $element_type = FALSE) {
foreach ($options as $option_value => $option_text) {
if ($element_type == 'tableselect' && isset($limits[$option_value])) {
$options[$option_value][0]['value'] = $this->getOptionsLimitLabel(
$option_text[0]['value'],
$limits[$option_value]
);
}
elseif (is_array($option_text)) {
$this->alterOptionsElementLabels($option_text, $limits);
}
elseif (isset($limits[$option_value])) {
$options[$option_value] = $this->getOptionsLimitLabel(
$option_text,
$limits[$option_value]
);
}
}
}
I altered the function to send in the element type, and if it's tableselect I access the label differently. There has to be done something similar to disable the field also.
Remaining tasks
(reviews needed, tests to be written or run, documentation to be written, etc.)
User interface changes
I guess this can be fixed with code only, so no ui changes.
API changes
I guess there will be no changes here either.
Data model changes
I guess there will be no changes here either.
Release notes snippet
(Major and critical issues should have a snippet that can be pulled into the release notes when a release is created that includes the fix)
Original report by [username]
(Text of the original report, for legacy issues whose initial post was not the issue summary. Use rarely.)
Comment | File | Size | Author |
---|---|---|---|
#8 | 3124729-8.patch | 18.77 KB | jrockowitz |
| |||
#2 | fix-tableselect-3124729-2.patch | 1.89 KB | andeersg |
|
Comments
Comment #2
andeersg CreditAttribution: andeersg at Bouvet commentedI have created a small patch with something that seems to work. It checks for webform element type and applies the comments and disabled attribute differently when it's a tableselect element.
Comment #3
andeersg CreditAttribution: andeersg at Bouvet commentedComment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached patch adds support for table single and a dedicated column for limits.
Comment #9
andeersg CreditAttribution: andeersg at Bouvet commentedI have tested the patch in #8 and it applies correctly to 8.x5.x-dev, the radio button is disabled when the limit is reached and the labels are updated correctly.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented