Hello community,
I have some trouble to manage the validation of a form.
In CMS, i have put switch button to activate or desactivate some radio question Yes/No
If swith on, it activate label + radio button, if not the line is hide.
The probleme is if i put requierd field, and for a line the switch button is on off, so the line not appear, but the hide code still and the form can’t be validate cause the radio wasn’t checked. Any idea ? shoul i use custom code or javascript ?
In this case 2 line swith off on CMS, i can’t validate forms
Form validation with hidden required fields can be handled effectively in Webflow. All form elements must be placed inside a form block for proper functionality. When using conditional visibility with switches, you can control which form fields are shown or hidden based on user interactions.
For required fields that may be hidden, consider these best practices:
Use the form block’s built-in validation settings
Ensure that hidden required fields are properly connected to their trigger conditions
Test the form thoroughly in preview mode to verify the validation behavior
You can find more detailed information about form anatomy and configuration in our form block documentation.
Hopefully this helps! If you still need assistance, please reply here so somebody from the community can help.
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("wf-form-Reference-Event");
form.addEventListener("submit", function (event) {
// Sélectionne tous les champs requis
const requiredFields = form.querySelectorAll("[required]");
requiredFields.forEach(function (field) {
// Vérifie si le champ est caché
if (field.offsetParent === null) {
field.removeAttribute("required"); // Supprime required pour éviter l'erreur
}
});
});
});
and
document.getElementById('wf-form-Reference-Event').addEventListener('submit', function() {
// Sélectionner tous les champs requis
const requiredFields = this.querySelectorAll('[required]');
requiredFields.forEach(function(field) {
// Vérifier si le champ est masqué
if (field.offsetParent === null) {
// Désactiver le champ masqué
field.disabled = true;
}
});
});
You’ll need to design your JS around your page structure, so I can’t guess where your code needs fixed.
The solution I gave is clean and doesn’t rely on anything like Webflow conditional invisibility, which would result from a very different setup.
If you need help with the coding, give me a shout in a direct message ( click my name here ), and I can share my details. I do a lot of custom form programming for freelancers & agencies here.