xxxxxxxxxx
To solve the problem, if you have a button on your page that does
something else other than submit or reset, always remember
to do this: <button type="button">
xxxxxxxxxx
Just because a form control is hidden doesn't mean it isn't required. And since
it is required, but hidden the browser can't focus the form control.
Every place you have .hide() change it to .hide().prop('required',false) to fix
your problem.
xxxxxxxxxx
document.getElementById('element_id').removeAttribute('required');
xxxxxxxxxx
if(document.getElementById('hidden_field_choice_selector_parent_element'.value==true){
document.getElementById('hidden_field').removeAttribute("required");
}
xxxxxxxxxx
const formControl = document.querySelector('[name="body"]');
if (formControl && formControl.validity.valid && !formControl.disabled) {
formControl.focus();
}