Skip to main content

How to add custom attributes to form fields via liquid

What is the liquid syntax for adding custom html attributes to forms and form fields? For example, I can generate an email field with a custom class with, e.g., 

{% email_field "email", class:"custom" %}

which for the donation form generates something similar to:

<input class="custom user-success" id="donation_email" name="donation[email]" type="email" value="">

I want to be able to add two custom html attributes, "required" and "pattern", and expected the following liquid to work:

{% email_field "email", class:"custom", required:"", pattern:"email" %}

Which outputs:

<input required="" class="custom user-success" id="donation_email" name="donation[email]" type="email" value="">

So that syntax seems to work for the required attribute, but not for the pattern attribute. Why? How do I add the pattern attribute to the output form field?

Official response from

You can use straight up HTML for input fields that need custom attributes and it will work just fine. You can't add custom attributes via liquid.

Share this post

Showing 3 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.