Score:1

Naming standard for long webform elements keys/options for simpler resuable coding

ph flag

I have a long multi-pages webform with mostly different groups of questions as radios, checkboxes, and likert types. I use computed_twig on some and jQuery on others for mostly either counting (how many of certain options/keys are selected) or summing up (the sum of keys values) selected values.

What's the most efficient strategy I can use and stick to so I can use less code/ re-use my code and need less re-coding for each group of questions (either with computed_twigs and/or jQuery).

The yaml code at this question is one example of my webform wizard pages.

And this is another sample/example where I need to count the number of all selected options of each name (e.g. how many "a" selected and how many "b"):

abqs:
  '#type': wizard_page
  '#title': 'test options length/count'
  '#open': true
  ab_1:
    '#type': radios
    '#title': 'choose one'
    '#options':
      a: a....
      b: b....
    '#options_display': buttons
    '#required': true
  ab_2:
    '#type': radios
    '#title': 'choose one'
    '#options':
      a: a....
      b: b....
    '#options_display': buttons
    '#required': true
  ab_3:
    '#type': radios
    '#title': 'choose one'
    '#options':
      a: a....
      b: b....
    '#options_display': buttons
    '#required': true
  ab_4:
    '#type': radios
    '#title': 'choose one'
    '#options':
      a: a....
      b: b....
    '#options_display': buttons
    '#required': true
  ab_5:
    '#type': radios
    '#title': 'choose one'
    '#options':
      a: a....
      b: b....
    '#options_display': buttons
    '#required': true
  abscore:
    '#type': computed_twig
    '#title': 'Selected a/b Counts'
    '#template': |-
      {# have yet to solve #}  
    '#ajax': true
    '#store': true
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.