JS try catch does not handle the form submission error "An invalid form control with the name 'somename' is not focusable. I have a tabbed page that shares one submit. When the page loads, the hidden, required field causes bad validation when I move from tab to tab. This would be easy to work around if it triggered a try/catch, and I could look for the message and act appropriately. However, the error skips right by the catch and cannot be handled.
var isValidForm = form.checkValidity();
if (!isValidForm) {
debugger;
let subbtn = document.getElementById('hiddenbtn');
let test = null;
try {
test = subbtn.click();
}
catch (ex) {
console.log(ex);
//if "An invalid form...not focusable" don't
//return but continue. We're ok with this error.
}
test;
return;
}
The catch should catch the error. But, instead, it skips right over it. Can anyone tell me how to detect this error in code without the big mess associated with adding and removing several required attributes?
You have "test = subtn.click()" in the try block, but you call it outside of the block.
Try calling the click function within the try block and you will catch the error as expected.