I have an acute problem on my website. In Google Chrome some customers are not able to proceed to my payment page. When trying to submit a form I get this error:
An invalid form control with name='' is not focusable.
This is from the JavaScript console.
I read that the problem could be due to hidden fields having the required attribute. Now the problem is that we are using .net webforms required field validators, and not the html5 required attribute.
It seems random who gets this error. Is there anyone who knows a solution for this?
For Select2 Jquery problem
The problem is due to the HTML5 validation cannot focus a hidden invalid element. I came across this issue when I was dealing with jQuery Select2 plugin.
Solution You could inject an event listener on and 'invalid' event of every element of a form so that you can manipulate just before the HTML5 validate event.
For Angular use:
ng-required="boolean"
This will only apply the html5 'required' attribute if the value is true.
In case anyone else has this issue, I experienced the same thing. As discussed in the comments, it was due to the browser attempting to validate hidden fields. It was finding empty fields in the form and trying to focus on them, but because they were set to
display:none;
, it couldn't. Hence the error.I was able to solve it by using something similar to this:
Also, this is possibly a duplicate of "Invalid form control" only in Google Chrome
Yet another possibility if you're getting the error on a checkbox input. If your checkboxes use custom CSS which hides the default and replaces it with some other styling, this will also trigger the not focusable error in Chrome on validation error.
I found this in my stylesheet:
Simple fix was to replace it with this:
I came here to answer that I had triggered this issue myself based on NOT closing the
</form>
tag AND having multiple forms on the same page. The first form will extend to include seeking validation on form inputs from elsewhere. Because THOSE forms are hidden, they triggered the error.so for instance:
Triggers
Alternatively another and foolproof answer is to use HTML5 Placeholder attribute then there will be no need to use any js validations.
Chrome will not be able to find any empty, hidden and required elements to focus on. Simple Solution.
Hope that helps. I am totally sorted with this solution.