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

Form fields in radio

Started by Muut Archive 10 years ago · 3 replies · 841 views
10 years ago

Hello,

I would like to make a multiple choice form with radio buttons, but I want to have optional text fields inside the radio text. Is there a simple way to do this in Grav?

Thanks,

Alex.

10 years ago

You can do anything that regular HTML can do with Grav. What exactly would the form look like in regular HTML?

10 years ago

Something like this
--- html
<html>
<body>

<form action="">
<input type="radio" name="option" value="1"> This is option 1 <input type="text" name="detail1"><br>
<input type="radio" name="option" value="2"> This is option 2 <input type="text" name="detail1"><br>
</form>

</body>
</html>

10 years ago

eg:

YAML
-
            type: radio
            label: 'Label '
            name: choice1
            text: 'Bla bla bla...'
            value: Choice
            classes: radio-input

conclusion in a template:

TWIG
{% if field.text %}
     <p class="custom-class">{{ field.text }}
      </p>
{% endif %}

or:

TWIG

<input type="radio"
                        {# required attribute structures #}
                        name="{{ (scope ~ field.name)|fieldName }}"
                        value="{{ value|e('html_attr')|join(', ') }}"
                        {# input attribute structures #}
                        {% block input_attributes %} 
                            {% if field.classes is defined %}class={{ field.classes }}" {% endif %}
                            {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
                            {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
                            {% if field.disabled %}disabled="disabled"{% endif %}
                            {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
                            {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                            {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                            {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
                            {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
                            {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
                            {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %}
                            {% if field.validate.message %}title="{{ field.validate.message|e|t }}"
                            {% elseif field.title is defined %}title="{{ field.title|e|t }}" {% endif %}
                        {% endblock %}
                        />
<label for="{% if field.id is defined %},{{ field.id|e }},{% else %},{{ field.name|e }},{% endif %}" class="">{{ field.label }}
                        </label>
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1356 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago