.selected class on click, ensuring proper visual feedback and form submission.To keep custom radio buttons selected after a click in Webflow when using custom styles or elements, you’ll typically use custom JavaScript to sync the visual states with the actual form element behavior.
data-radio-group="choices") to each custom element.data-radio-value="option1") to define the value it represents.
custom-radio), which is required for mutual exclusivity.radio-option1, radio-option2), matching the data-radio-value.
document.querySelectorAll('[data-radio-group="choices"]').forEach(el => {
el.addEventListener('click', () => {
const value = el.getAttribute('data-radio-value');
// Deselect all custom elements
document.querySelectorAll('[data-radio-group="choices"]').forEach(btn => {
btn.classList.remove('selected');
});
// Add selected class to clicked element
el.classList.add('selected');
// Check the actual Webflow radio input
const realRadio = document.getElementById('radio-' + value);
if (realRadio) {
realRadio.checked = true;
}
});
});
.selected class in Webflow to visually show which button is selected.
To keep custom radio buttons selected in Webflow, sync custom-styled elements with native hidden radio inputs using JavaScript. Attach click events to toggle a .selected class and update the corresponding hidden radio input’s checked state for proper form submission.