I have a webform with a set of radio buttons (group).
I need to conditionnaly select one of the radio buttons based on the value of another field. I thought I would use Javascript to achieve this task.
The radio group is set to be required.
Visually, the radio button gets selected as expected, but when I submit the form, I get and error that says "Field my-radio-field is required". And the webform is displayed below the message and I can see that my radio field has no option selected.
Here is my Javascript for reference:
Drupal.behaviors.installationForm = {
attach: function(context) {
once('installation-form', '.webform-submission-installation-form', context).forEach(function(element) {
// On field change
$('input[name="drivers_installation"]', element).on('change', function() {
// Condition
if ($('#edit-drivers-installation-server', context).is(':checked')) {
// Select radio button
$('#edit-my-radio-field', context).prop('checked', true);
}
});
});
}
};
I must be missing something. What is the correct way of selecting a webform radio button with Javascript?