How can I add a css class directly to the INPUT tag generated by {{ input|raw }} from the accessible template of the sprout form plugin? I do not wish to add the class to a surrounding div.
I ended up looping through the form fields, which works almost but lacks the field types:
This is my field.html. It seems I cant get the field.type thus it defaults to text for all fields.
{%- do craft.sproutForms.addFieldVariables(_context) -%}
{%- set label = field.name ?? null %}
{%- set name = field.handle ?? null %}
{%- set type = field.type ?? 'text' %}
{%- set required = field.required is defined and field.required ? true : false %}
{%- set id = renderingOptions.id ?? name %}
{%- set class = renderingOptions.class ?? name %}
{%- set value = entry is not empty ? entry.getFieldValue(name) : null %}
{%- set errors = entry is not empty ? entry.getErrors(name) : null %}
{%- namespace field.getNamespace() -%}
{%- if field.isPlainInput() -%}
{{ input|raw }}
{%- else %}
{% if label -%}
<div class="heading">
{% if label -%}
<label{% if name %} for="{{ name }}"{% endif %}>
{{- label|raw|t('sprout-forms') -}}
</label>
{%- endif -%}
</div>
{% endif -%}
<div class="row">
<div class="col-md-4">
<input type="{{type}}" name="{{name}}" class="{{class}}" {%- if required %} required{% endif -%}>
</div>
</div>
{% include "errors" with {
errors: errors,
name: name
} %}
{%- endif -%}
{%- endnamespace -%}
In the tab.html which calls uses the field.html:
{%- for tab in tabs -%}
{%- set layoutFields = tab.getFields() %}
<section class="tab">
{% set fieldOptions = {
"class": "form-control",
"errorClass": "has-error",
"data": {
"hidden": "false",
}
} %}
{% for field in layoutFields -%}
{{- craft.sproutForms.displayField(form, field, fieldOptions) }}
{%- endfor %}
</section>
{%- endfor -%}
This is all based on the default "accessible" template from the plugin. While I know I could put the fields manually in the template, I would prefer to learn how this is actually done "nicely". Thanks!