13
votes

I'm facing the well known Chrome's "not-focusable-input" error but my situation is different from the explained in the other post I could find there.

I have this error message duplicated first on a well pointed input, this input has no required attribute: The code:

<fieldset>
    <label>Total (montaje incl.)</label>
    <input type="number" id="priceFinal" name="priceFinal"> €
</fieldset>

The error: An invalid form control with name='priceFinal' is not focusable.

While the user is filling the form this field gets its value by a js script with jquery. The user type a size in another input, the script do its maths with the size value and then put the outcome in the 'priceFinal' input with the jquery function: .val()

In the browser we can see that the input is correctly filled and no errors are displayed at that time. And with the 'novalidate' solution everything goes fine, so it couldn't be responsible for the nofocusable error, I think.

Then I got the same error with an input with no name which I didn't write and doesn't exist in my DOM:

An invalid form control with name='' is not focusable.

This is weird because the only input without name in my form is the type:submit one

<input type="submit" class="btn btn-default" value="Ver presupuesto" />

I have a few required fields but I've always checked that their are all filled when I send the form. I paste it just in case it could help:

<fieldset>
    <input type="text" id="clientName" name="clientName" placeholder="Nombre y apellidos"  class="cInput" required >
    <input type="text" id="client_ID" name="client_ID" required placeholder="CIF / NIF / DNI" class="cInput">
</fieldset>
<fieldset>
    <input type="text" id="client_add" name="client_add" placeholder="Dirección de facturación" class="addInput" required >
</fieldset>

<fieldset>
    <input type="text" id="client_ph" name="client_ph" placeholder="Teléfono" class="cInput" required>
    <input type="email" id="client_mail" name="client_mail" placeholder="Email" class="cInput" required> 
</fieldset>

The novalidate solution clears the error but it doesn't fix it, I mean there must be a way to solve it with no hacks.

Any one have any idea of what's might going on? Thanks

8
Do you have a button control that is being clicked at some point while using the form? - If yes, does the button have its type attribute correctly set? - If a button does not cause form submission, you must explicitly set its type attribute with the value button: <button type="button"></button>.Igwe Kalu

8 Answers

19
votes

I had the same problem, and everyone was blaming to the poor hidden inputs been required, but seems like a bug having your required field inside a fieldset. Chrome tries to focus (for some unknown reason) your fieldset instead of your required input.

This bug is present only in chrome I tested in version 43.0.2357.124 m. Doesn't happen in firefox.

Example (very simple).

<form>
  <fieldset name="mybug">
    <select required="required" name="hola">
      <option value=''>option 1</option>
     </select>
    <input type="submit" name="submit" value="send" />
  </fieldset>
</form>

An invalid form control with name='mybug' is not focusable.

The bug is hard to spot because usually fieldsets don't have a name so name='' is a WTF! but slice piece by piece the form until I found the culprid. If you get your required input from the fieldset the error is gone.

<form>
    <select required="required" name="hola">
      <option value=''>option 1</option>
     </select>

  <fieldset name="mybug">
    <input type="submit" name="submit" value="send" />
  </fieldset>
</form>

I would report it but I don't know where is the chrome community for bugs.

5
votes

Thanks to this post, I saw that my problem also rested with Chrome trying to focus on my fieldsets, instead of the input field.

To get a better response from the console:

  • Assign every DOM element a new name
  • Set every input & select style.display to 'block'
  • Changed the type of input[type="hidden"] elements to 'text'

    function cleanInputs(){
        var inputs  = document.getElementsByTagName( 'input' ),
            selects = document.getElementsByTagName( 'select' ),
            all     = document.getElementsByTagName( '*' );
        for( var i=0, x=all.length; i<x; i++ ){
            all[i].setAttribute( 'name', i + '_test' );
        }
        for( var i=0, x=selects.length; i<x; i++ ){
            selects[i].style.display = 'block';
        }
        for( var i=0, x=inputs.length; i<x; i++ ){
            if( inputs[i].getAttribute( 'type' ) === 'hidden' ){
                inputs[i].setAttribute( 'type', 'text' );
            }
            inputs[i].style.display = 'block';
        }
        return true;
    }
    

In the console, I ran cleanInputs() and then submitted the form. The result, from the console, was:

An invalid form control with name='28_test' is not focusable.

An invalid form control with name='103_test' is not focusable.

Then, switching over to the Web Developer "Elements" view, I was able to find "28_test" and "103_test" (both fieldsets) -- confirming that my problem was a required input field, nested inside a fieldset.

1
votes

While I was writting the question I realized one thing: the value the script was putting into the 'priceFinal' field sometimes was a decimal number.

In this case the solution was to write the step attribute for this input:

... step="any" ...

Step on w3s

So this 'nofocusable' bug is not only a required and hidden fields issue, it's also generated by format conflicts.

1
votes

Nach gave me the best pointer... (y) I also had a input type="number" with step="0.1" and the console shows me this error while validating: An invalid form control with name='' is not focusable.

remove the step="0.1" on the element and now the form can be validated

1
votes

I had the same issue so I removed required="required" from the troublesome fields.

1
votes

If you get the error when jQuery function is executed, try to put "return false" on your function, or function(e) { e.preventDefault(); ... }

0
votes

i had this issue once. to fix it, add

novalidate

as an attribute to the form. e.g

<form action="" novalidate>
....
</form>
-2
votes

Here is the solution....

<form>
  <input type="text" ng-show="displayCondition" ng-required="displayCondition"/>
</form>

Many people do not realize that passing false into ng-required disables the directive.