Using likert tables in forms a lot. Would it be possible to have multiselect here? So user can select multiply values for each question?

I imagine this can probably be done with checkboxes or multiselectable lists, but we need same likert style presentation of the form.
If someone knows of other ways to do the same, input welcome :)

Comments

gpikelis created an issue. See original summary.

jrockowitz’s picture

The backend data storage of submission data can't support likerts with multiple values.

There is no easy workaround even with custom code.

You might be able to fake a Likert using checkboxes layed out horizontally and side-by-side

jrockowitz’s picture

Status: Active » Closed (won't fix)
gpikelis’s picture

OK. Fair enough :)
In a way "table select" element saving data the way I need. So an array of table selects could be used to fake likert.

Is it possible to get it horizontal?

jrockowitz’s picture

For the amount work needed to get a horizontal table select, I would create a new element or try to place my checkboxes elements in a container and theme it to look like a table.

rd.michael’s picture

I know this question is pretty old but I'm wondering if you can provide insight into creating a custom element. I've actually gotten something working but want to know if I'm on the right track or if there are any gotchas that I'm missing.

  • I created a custom element that extends WebformLikert (both Element and WebformElement).
  • In the class that extends Drupal\webform\Element\WebformLikert I am overriding the method processWebformLikert so that I can change the radio elements to the checkbox elements. The trick, I discovered, to get checkboxes sending the correct data to the server was to update the '#parents' key to a multi multi dimensional array. i.e. '#parents' => [$element['#name'], $question_key, $parent_inc] where $parent_inc is simply a delta.
  • In the same class I had to override the valueCallback method, simply to remove the conditional check for is_scalar and the casting of the value to a string (since it's now an array).
  • I could probably change up this next implementation a bit, but what I had to do next was update how this is stored in the WebformSubmissionStorage class. I added a simple conditional for my element in the save and load methods. The reason I had to do this was b/c my values are sent in this format [question_id][property_id][delta] and there is no current conditional that stores things in that format. The closest I could find was the '#webform_composite' plus '#webform_multiple' both being true, but I'm not sure I can override the '#webform_multiple' value. In addition I would have to change my format from [question_id][property_id][delta] to [question_id][delta][property_id] and I'm not sure it makes sense to do that or if it's possible.
  • After all that everything was saving and loading fine in my forms, but I noticed it didn't look right in the previews (html, plain text, etc), so...
  • In my class that extends Drupal\webform\Plugin\WebformElement\WebformLikert I overwrote the formatHtmlItem and formatTextItem methods to account for the array values instead of expecting a scalar.

All that to say, do you think I'm missing anything? And if not, would you be open to a patch if I could integrate this into the WebformLikert element (or a new element)?

jrockowitz’s picture

Version: 8.x-5.0-beta7 » 8.x-5.x-dev
Status: Closed (won't fix) » Active

@researchanddesign.michael Your solution makes sense. I am optimistic we could add support for #multiple property to the existing Likert element.

A patch would be welcomed but most likely not committed until Webform 8.x-6.x which I hope to start working on after the New Year.

jrockowitz’s picture

Status: Active » Closed (won't fix)

The level of effort required to add another layer of complexity to how submission data is saved and loaded does not seem worth being able to support a multi-value Likert element.