Advanced grid (multiple choice, conditionals, non-homogeneous options)

Created on 7 October 2015, over 8 years ago
Updated 2 June 2023, about 1 year ago

Several time have I started down the path of supporting conditionals for grid questions -- both as source rules and as target actions. It is very involved and results in complicated, ugly code. Then I am upon the idea of using a grid as a container for the questions which are just Select Options components.

The attached patch implements "Grid (advanced)", machine name grid2, which has this functionality. Because the D7 component API is not object oriented, it was a bit difficult since much of grid2 is the same as grid. I have attempted to write it in such a way that the D8 version can use inheritance to so that grid2 extends grid.

Pros:

  1. The nested Select Options components may accept multiple options (checkboxes).
  2. Checkboxes and radios may be mixed in the same grid2.
  3. Some checkboxes / radios may be missing some options, or have extra options. grid2 will consolidate the options from all nested Select Options components.
  4. Conditionals can operate with the nested Select Options components as if they weren't within a grid.
  5. Individual questions can be required and others not.
  6. Components other than Select Options may be nested in a grid and are rendered within the grid, with a colspan that appears where the radios would otherwise be.

Cons:

  1. Harder to configure. 10 questions will require 11 components -- a grid2 and 10 select's.

I offer this for comment, especially on any implementation details, and of course for testing. I did enhance the grid component in places to handle some of the features of grid2. This avoided have two very-similar functions (one in grid and the other in grid2). I could be convinced that the duplication of code is better so that grid is changed as little as possible.

I have not tested with the option element module. Formbuilder will presumably need an update.

✨ Feature request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States DanChadwick

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡ΉPortugal miguelbraga

    Dear all,

    I'm sorry for reopening this but I'm confused.
    (I'm on D7 and latest webform) I'm trying to give set a condition based on a webform grid component value, eg:

    Color usage
    Never Almost NeveR Sometimes Fairly Often Very Often
    Do you use red?
    Other color?

    With the "other color" question I want to show a textfield if the user selects all options rather than never (to specify color).
    It's a basic example but translates what I want to achieve with medical jargon.

    Is this possible? the field doesn't appears listed in the first conditional field!

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    This sounds like a support request. Please open a new ticket. Support requests are always normal priority.

Production build 0.69.0 2024