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:

  1. Create webform with "Table select" element.
  2. Add a "Options Limit" handler and set limits to the elements.
  3. 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.)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andeersg created an issue. See original summary.

andeersg’s picture

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

andeersg’s picture

Status: Active » Needs review

  • 03155e9 committed on 3124729-tableselect-options-limit
    Issue #3124729 by andeersg: Option Limit broken for Tableselect
    

  • 76f5010 committed on 3124729-tableselect-options-limit
    Issue #3124729 by andeersg: Option Limit broken for Tableselect
    

  • 9b26679 committed on 3124729-tableselect-options-limit
    Issue #3124729 by andeersg: Option Limit broken for Tableselect
    

  • a2457cd committed on 3124729-tableselect-options-limit
    Issue #3124729 by andeersg: Option Limit broken for Tableselect
    
jrockowitz’s picture

The attached patch adds support for table single and a dedicated column for limits.

andeersg’s picture

Status: Needs review » Reviewed & tested by the community

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

  • jrockowitz authored 3c06225 on 8.x-5.x
    Issue #3124729 by andeersg, jrockowitz: Option Limit broken for...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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