Divi Form Builder doesn’t come with a range field. But with a little JavaScript magic, you can turn a number field into a Range Slider.
For this example, I am making an Area field. We will need 2 fields:
- A Content field to display the selected value.
- A Number input field.
Follow the steps below and customize it according to your requirements.
Step 1: Start by creating a Content field:
- Add a field in your Form module
- Set a unique
Field ID
and note it down. For my example, I am using the IDsq_feet_value_placeholder
- Change the Type to Content
- Change the
Content Type
toCode
keep things clean
Step 2: Create the Number field.
This will be transformed into the range slider using our JS.
- Add another field
- Set the
Field ID
for this field and note it down. Make sure it’s unique and doesn’t have any spaces. I’m usingarea_feet
for my example. - Set the
Type
toNumber Input Field
. - Add the Minimum and Maximum values for the field.
- Additionally, you can also set a
Number Increase Step Value
.
Step 3: Add the code
Now we need to add the JavaScript:
- Start by adding a code module. Make sure it is placed after the form and not before.
- Add the following code in the module. Change it according to the field IDs.
const sq_feet_input = document.getElementById(‘de_fb_area_feet’); // change area_feet to the number field ID
let sq_feet_value_output = document.getElementById(‘de_fb_sq_feet_value_placeholder_wrapper’); // change sq_feet_value_placeholder to the content field ID.
const value_suffix = ‘ Sq feet’ // change Sq feet to whatever suffix you want, or make it blank but don’t remove the line’
sq_feet_input.type = ‘range’;
sq_feet_value_output.textContent = sq_feet_input.value + value_suffix;
sq_feet_input.addEventListener(‘input’, function() {
sq_feet_value_output.textContent = this.value + value_suffix;
});
Don’t forget to change the values above according to your field IDs.
Step 4: Add the CSS:
Now you need to add some CSS to make the range slider properly visible. You can add it either in Divi
> Theme Options
> Custom CSS
, Page CSS, or inside Free-Form CSS
inside the Form module itself:
.de_fb_form input[type=range] {
appearance: auto;
}
That’s it! Now you should have a working range slider like this:
Conclusion
There you go! That is all there is to it to add a range slider to your Divi Form Builder forms. Divi Form Builder is by far the best and easiest way to create amazing forms in the Divi Theme, so be sure to check it out!