Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Form Plugin: customize field type checkboxes

Started by Sebastian 6 years ago · 2 replies · 886 views
6 years ago

Hey guys,
I'm building a large form right now. I need to modify the checkboxes field type. Which works fine, if I copy the folder and template file to my own theme. But I need to create a new field type, something like checkbox-images, to also keep the original checkboxes field type.

So I copied the modified checkboxes folder with the checkboxes.html.twig file and renamed folder and file to checkboxes-images, then I changed the field type inside the form.md from

YAML
      wert:
        type: checkboxes
        display_label: false

to

YAML
      wert:
        type: checkboxes-image
        display_label: false

The rendering of my checkbox fields frontendwise is working as aspected.
Unfortunately the selected checkboxes fields do not get rendered inside the email sent by the form. I already changed the data.html.twig template to

TWIG
   {% block field_value %}
          {% if field.type == 'checkboxes-images' %}
            <ul>
              {% set use_keys = field.use is defined and field.use == 'keys' %}
              {% for key,value in form.value(scope ~ field.name) %}
                {% set index = (use_keys ? key : value) %}
                  <li>
                      {{ field.options[index].name|e }}
                  </li>
              {% endfor %}
            </ul>
          {% elseif field.type == 'checkbox' %}

But this does not work. At this point I'm stuck. Everything works if I change the original file, but if I copy the file and rename the `field type, the checkboxes field does not get rendered inside the email. Any help? 😅

4 years ago

Did you find a solution?

4 years ago

Not really… it works if you use the original checkboxes field, but if you try to use a different template it doesn't work. Looks like somewhere inside the form plugin is some hidden magic I couldn't find.

Maybe @rhuk has an idea? 🙂

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1135 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 60 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 132 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 108 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 127 7 months ago