Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Consider an example where you want the user to rate 3 categories so that the total equals 100.

Part 1: The numbers you want to add

Create a "Number" field for each category you want to add. For each one, you probably want to set additional settings, such as the following

...

Repeat these steps for every category you want to add.

Part 2: The Sum field

This is the field that does the work of adding the numbers. Because it is going to use math, it has to rely on the Twig engine that works behind the scenes in Drupal. Under the "Computed" section of the Fields creation screen, choose "Computed Twig."

...

  1. Twig uses the characters {{ and }} to indicate that you're giving it data to process, so surround this field with those.
  2. Then use the keys for the form fields that you created in step 1 (in the format "data.form_field_key"), and follow them with + signs to tell Twig to add them.
    The code will look something like this:

    Code Block
    {{ 
    data.first_field +
    data.second_field + 
    data.third_field
    
    }}


  3. Settings:
    1. Mode: Plain text. This will help if you need to validate this field or use it for conditions on other fields
    2. Remove whitespace around the Computed Value and HTML tags. This also helps with validation and conditions
    3. Automatically update the computed value using Ajax? Usually you'll want to check this box; it's what enables the form to add the numbers as the user enters them.

...

    1. Otherwise, it will only be summed after the form is submitted.


Filter by label (Content by label)
showLabelsfalse
max5
spacesWS
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "webform" and type = "page" and space = "WS"
labelsWebform

...