Advanced Form Field Creation in Webflow: HTML Embed Tutorial | Webflow Forms Masterclass Ep. 4

Published on
May 27, 2021

Building Advanced Form Fields in Webflow

Welcome to the fourth episode of our Webflow Forms Masterclass series. In this episode, we will be delving into more advanced form fields that can only be achieved using the HTML embed element. If you are interested in learning more about these advanced form fields, then this tutorial is for you.

Getting Started

Before we dive into the advanced form fields, be sure to catch up on our previous episodes if you haven't already. In the earlier episodes, we covered the basic form elements and multi-stage forms, as well as conditional fields using JavaScript. You can find the full playlist on our YouTube channel to catch up with all the basics and be up to speed with us.

My name is Samuel Gregory, and on this channel, we focus on all things front-end development, including no-code and accessibility. If these topics interest you, consider subscribing to our channel for more content.

Without further ado, let's jump into creating some advanced form fields.

Field Set and Legend Elements

The first advanced form field we will explore is the <fieldset> and complementary <legend> element. These elements are important for accessibility as they group form fields together, indicating that they are related to each other. For example, you might have multiple form fields for an address, and by using the fieldset and legend, you can group these fields to convey their relationship to assistive technology users.

The downside of using the fieldset and legend in Webflow is that you can't directly use the native Webflow form fields. However, with HTML embed, you can achieve the same result by ensuring that the elements within the fieldset have the appropriate classes. Let's take a look at how to implement this in Webflow.

Inside the HTML embed element within your form, you can add the following code:

<fieldset>  <legend>Address</legend>  <!-- Your form input fields go here --></fieldset>

With the fieldset and legend in place, you can then create your address fields such as line one, line two, city, and zip code within the fieldset. Remember to ensure that each input has a label and is properly linked using the for attribute matching the id of the input element.

To enhance the visual styling of these form fields, you can apply custom classes to the elements within the fieldset, ensuring a cohesive design for your form.

Data List Element

Next, let's explore the <datalist> element, which acts as an auto-complete feature for a text input. This element allows users to type in a text input field and suggests options based on the predefined list, providing an intuitive user experience.

To implement a datalist in Webflow, you can add the following code within the HTML embed element:

<label for="fruits">Fruits</label><input type="text" list="fruit" name="fruit" id="fruits"><datalist id="fruit">  <option value="apple">  <option value="banana">  <option value="pear">  <!-- Add more options as needed --></datalist>

In this example, the input field is associated with the datalist using the list attribute, which references the id of the datalist. This allows users to type in the input field and select from the suggested options provided by the datalist.

After implementing the datalist, you can further customize the styling and behavior to ensure a seamless user interaction in your Webflow form.

Output Element

Now, let's discuss the <output> element, which is useful for creating interactive web pages. The output element displays the result of one or more form fields, and its value can be dynamically updated using JavaScript.

To incorporate the output element into your Webflow form, you can use the following HTML markup within the HTML embed element:

<input type="range" value="50" id="range"><input type="number" value="10" id="number"><output for="range number" id="result"></output>

In this example, the output element is linked to the input fields using the for attribute, which specifies the IDs of the form fields contributing to the output. Additionally, you can define the aria-live attribute to indicate how dynamic updates should be announced to users who rely on screen readers.

To achieve dynamic updates for the output element, you will need to incorporate JavaScript, either with or without jQuery, depending on your preference. The JavaScript logic involves capturing input changes from the associated form fields and updating the output element accordingly.

By utilizing the output element in your Webflow forms, you can create engaging and informative user interfaces, especially for scenarios that require real-time data representation.

Optgroup Element

Lastly, let's explore the <optgroup> element, which allows you to group options within a select input. The optgroup element is not natively supported in Webflow, but you can leverage the HTML embed element to implement it and enhance the organization of options within a select field.

To integrate optgroup in Webflow, you can use the following HTML structure within the HTML embed element:

<select>  <optgroup label="Swedish Cars">    <option value="volvo">Volvo</option>    <option value="saab">Saab</option>  </optgroup>  <optgroup label="German Cars">    <option value="mercedes">Mercedes</option>    <option value="audi">Audi</option>  </optgroup>  <!-- Add more optgroup and option elements as needed --></select>

In this example, the select input is organized into distinct groups, such as Swedish Cars and German Cars, using the optgroup element, providing a structured presentation of options within the dropdown menu.

While the native support for optgroup in Webflow is limited, leveraging the HTML embed element empowers you to create more sophisticated select inputs with organized and categorized options.

Conclusion

In conclusion, by exploring these advanced form fields and elements, you can expand your capabilities in building complex and interactive forms within Webflow. Remember to consider accessibility and user experience when implementing these elements, and feel free to customize the styling and behavior to align with your design preferences.

We hope this tutorial has provided valuable insights into leveraging HTML embed elements to create advanced form fields in Webflow. If you have enjoyed this episode, be sure to like and subscribe for more content. Feel free to share your creative use cases of these elements and reach out with any questions or clarifications in the comments section.

Thank you for joining us, and happy no coding in Webflow!

[Music]

That's it for our advanced form fields tutorial. We hope you found it helpful and informative. If you have any questions or need further assistance, feel free to reach out to us.

Happy building in Webflow!