Problem

Sometimes, users need to select options using a visual representation of the options. The image select element only allows users to pick images. In particular use case users should be able to visual select seats, rooms, parts of the body, etc.…

Solution

Provide as Webform Options Custom element where any HTML or SVG markup to be converted into a selectable single or multiple options elements.

Here is a conceptual prototype.

TBD

  • Entity Reference should also be supported.

Features

  • Select single
  • Select multiple
  • Extract options from markup
  • Descriptions will be supported
  • Tooltips will be supported

Notes

  • Extends a select element.
  • Hidden select menu will be used to handle backend integration and validation.
  • Options Custom element will support hover, click, selected, and disabled states.
  • The #options could be extracted from the HTML/SVG markup
  • HTML/SVG markup could also support Twig.
  • HTML/SVG markup will support any tags. Only trusted users should be allowed to create these elements.
  • HTML/CSV markup can be pasted in or linked to
  • Might need to allows markup to be preprocessed.
  • Might have to use a jQuery plugin.
  • Preview will NOT show the visual HTML/SVG markup.

Tasks

  • Create webform_options_custom module.
  • Create WebformOptionsCustom element plugin
  • Create WebformOptionsCustom webform element plugin
  • Create WebformOptionsCustomEntity element plugin
  • Create WebformOptionsEntityCustomEntity webform element plugin
  • Create HTML markup example
  • Create SVG markup example
  • Create image map example
  • Create JS and CSS libraries
  • Support conditional disabled/enabled states.
  • Create webform_options_custom_examples module
  • Apply accessibility aria attributes.

User Acceptance Test

  • Enable the Webform Custom Options module
    /admin/modules
  • Go to 'Custom options' configuration page
    /admin/structure/webform/config/options_custom/manage
  • Confirm U.S states custom options is listed
    /admin/structure/webform/config/options_custom/manage
  • Edit U.S. states, change label, checkboxes, etc...
    /admin/structure/webform/config/options_custom/manage/us_states/edit
  • Create new custom markup options can "Test"
    /admin/structure/webform/config/options_custom/manage/add
    <div data-id="one" data-name="One" style="margin: 5px 0; border: 1px solid #000; padding: 10px;">One</div>
    <div data-id="two" data-name="Two"style="margin: 5px 0; border: 1px solid #000; padding: 10px;">Two</div>
    <div data-id="three" data-name="Three"style="margin: 5px 0; border: 1px solid #000; padding: 10px;">Three</div>
    
    one: 'One -- This is a custom description.'
    two: 'Two -- This is a custom description.'
    three: 'Three -- This is a custom description.'
    
  • Preview 'Test' custom options and confirm tooltips are being pulled from options.
    /admin/structure/webform/config/options_custom/manage/test/preview
  • View 'Example: Custom Options' and confirm custom options input is working as expected.
    /form/example-options-custom
  • Confirm custom options element edit form
    /admin/structure/webform/manage/example_options_custom/element/states/edit

Comments

Mile3 created an issue. See original summary.

jrockowitz’s picture

Title: SVG Form Element » Webform Custom Options
Issue summary: View changes

Mile3 would like to sponsor development.

https://www.drupal.org/project/webform/issues/2907663

jrockowitz’s picture

Title: Webform Custom Options » Allow custom HTML/SVG markup to be used as options
Mile3’s picture

Thanks Jacob. Looks good.

A very important request:

1) I hope we can still apply options limits (which I believe is addressed if this is a select field)

2) We have to be able to get data from prior submissions in the tooltip (probably using an entity reference view, but we're open to other suggestions).

Use case: Exhibit hall. If a company is choosing an exhibit booth space, they should be able to hover over booths that have already been reserved to see who is going to be nearby and avoid conflicts.

In addition, the Mile3 team would like to offer to provide some common SVG field presets (countries, states, etc) once this is off the ground.

jrockowitz’s picture

1) Options limits will definitely be supported. This is why the disabled/enabled states need to implemented.

2) The tooltip is going to be powered by the option text + description. One challenge might be supporting HTML markup in the tooltip.

For entity references, I think I am going to build the relationship using the options text and not the the option value (ie node id).

For example, in the SVG you would only have data-option-text attributes. For the entity reference options I would add data-option-value which would be the entity ID.

<rect data-option-text="Booth 1" /> would be magically change to <rect data-option-text="Booth 1" data-option-value="1234" />

Please attach as many example as you want to this ticket.

Mile3’s picture

StatusFileSize
new59.75 KB

Here is a sample of the United States, and a conference room with Tables. Ids are provided.

More examples of maps can be found here: https://simplemaps.com/resources/svg-maps

jrockowitz’s picture

Issue summary: View changes

  • a4cafc6 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 6d8b4ca committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • d46214c committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 093fd64 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • 0991020 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • cb2912c committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • d21a32c committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • fbdecc2 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 873ae01 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 14b4776 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 5b71eba committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • adb8bcd committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • ed1c7f4 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • bb9cf98 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 3c0743d committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 85554d5 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 4cee762 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 92b5b51 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 1d979cd committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 735d606 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • b91c93a committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

Issue summary: View changes
jrockowitz’s picture

Issue summary: View changes
jrockowitz’s picture

Issue summary: View changes

  • a262ec3 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 1e11ede committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 538545f committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 39d3345 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 6d9d239 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
  • d4033c3 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • b4b73a4 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 88ac0db committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • a301907 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • e33716a committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new551.09 KB

  • 4bb1bd5 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 24c3d02 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 3bba27e committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 2083d0d committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new562 KB

  • 914fae2 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • ea57272 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 3b3327a committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 6ff5566 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 386b73d committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 193a1a6 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new579.91 KB

Status: Needs review » Needs work

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

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new579.98 KB

  • ce73d2b committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 087f8c4 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new580.13 KB

  • d9e10bd committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • fc987d0 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 544d5f5 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new584.57 KB

  • 73795b2 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 58714be committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 60c9311 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 6af1f48 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 9b334aa committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new595.26 KB

  • 65f6c5c committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new0 bytes

  • 7b32d83 committed on 3081795-webform-options-custom
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...
jrockowitz’s picture

StatusFileSize
new594.96 KB

  • jrockowitz authored afe59d2 on 8.x-5.x
    Issue #3081795 by jrockowitz, Mile3: Allow custom HTML/SVG markup to be...
jrockowitz’s picture

Status: Needs review » Fixed

  • 8ba2c37 committed on 8.x-5.x
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

  • 121ac40 committed on 8.x-5.x
    Issue #3081795 by Mile3: Allow custom HTML/SVG markup to be used as...

Status: Fixed » Closed (fixed)

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