Radio input on Contact Plugin

wcd_calum - 5 months ago

Trying to make sense of the example given here (https://pyrocms.com/documentation/contact-plugin/latest), what's the correct way to add radio buttons for this and could it be added to the documentation?

ryanthompson - 5 months ago

That is showing you that you can configure fields just as you would (or similar) in migrations:

https://pyrocms.com/documentation/contact-plugin/latest#introduction/configuration/fields

So for example you could use the select field type with radio mode: https://pyrocms.com/documentation/select-field-type/latest#introduction/configuration

wcd_calum - 5 months ago

Thanks that helped. This is how I have done it for my custom layout:

{%  set form = form('example').fields({
    'querytype': {
        'label': 'Query type',
        'required': true,
        'type': 'anomaly.field_type.select',
        'config' : {
          'options' : {
            'opt1' : 'Option 1',
            'opt2' : 'Option 2'
          },
        },
        'default_value' : 'opt1',
        'mode'          : 'radio'
    }
})
%}
{{ form.open|raw }}
 <label for="opt1"><input id="opt1" class="form-check-input" name="querytype" value="opt1" type="radio"> Option 1</label>
 <label for="opt2"><input id="opt2" class="form-check-input" name="querytype" value="opt2" type="radio"> Option 2</label>
{{ form.actions|raw }}
{{ form.close|raw }}

ryanthompson - 5 months ago

If you could @wcd_calum format that with markdown so others can better read / use it ^_^

Glad it helped! FYI that's kinda the same principle in defining fields everywhere - very little difference depending on where you are. Only real difference I guess is defining a field for a migration vs for a UI component (and even still very much exactly the same but for example field migrations only have limited columns).