Hello,

i'd need to add some descriptions for single options in checkboxes or radios elements. Just found out it is possible in forms thanks to this: https://www.drupal.org/node/2531656.

i read this was already suggested and closed https://www.drupal.org/node/1721998, but since the 8 version of Webform has changed a lot of things, well... why not trying again?

i think i can help with patches and code, would just like to have a couple hints on where to start from... Could anyone give me suggestions?

thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joey-santiago created an issue. See original summary.

jrockowitz’s picture

This is going to be really difficult to fully support. I am not exactly sure where to begin.

jrockowitz’s picture

I am so tempted to suggest we add a description delimiter that automatically generates a checkbox/radio description.

#options:
  one: One -- This is a description.
  two: Two -- This is a description.
  three: Three -- This is a description.

This is a "hacky" solution but very easy to implement and support.

...then we could take it a step further and support the help tooltip (ie '?' ) using a different delimiter.

#options:
  one: One || This is a help.
  two: Two || This is a help.
  three: Three || This is a help.
jrockowitz’s picture

The \Drupal\webform\Element\WebformElementOptions could be extended to support option descriptions.

I am leaning toward the YAML syntax being...

#options:
  one: One -- This is a description.
  two: Two -- This is a description.
  three: Three -- This is a description.
#options_display: (help|description)

  • jrockowitz committed 01a92c4 on 2910504-options-descriptions
    Issue #2910504: Options descriptions
    
jrockowitz’s picture

Status: Active » Needs review
FileSize
141.28 KB

Status: Needs review » Needs work

The last submitted patch, 6: options_descriptions-2910504-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
141.28 KB

  • jrockowitz committed 8a4d3a3 on 2910504-options-descriptions
    Issue #2910504: Options descriptions
    

  • jrockowitz committed d392978 on 2910504-options-descriptions
    Issue #2910504: Options descriptions. Write tests
    
jrockowitz’s picture

  • jrockowitz committed fe4735b on 8.x-5.x
    Issue #2910504 by jrockowitz: Options descriptions
    
    Signed-off-by:...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Adding descriptions or help text to checkboxes and radios is now fully supported. Please download the latest dev release to review.

Status: Fixed » Closed (fixed)

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

joey-santiago’s picture

Thanks a lot, works perfectly!

as i wanted them to go on a new line in stead of being "immersed" in the title text, i went this way:

1: added an element to the form_element_label.html.twig
2: used template_preprocess_form_element_label() to split the title by WebformOptionsHelper::DESCRIPTION_DELIMITER and extract my description

hope it can help others :)