An invalid form control with name='' is not focusable. WITHOUT ANY REQUIRED OR HIDDEN INPUTS

67,459

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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

Share:
67,459
nach
Author by

nach

Updated on July 17, 2022

Comments

  • nach
    nach almost 2 years

    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

  • David Baucum
    David Baucum almost 9 years
    Thanks, this led me down the path of just removing the fieldset. After I did that all my problems went away. Information about reporting Chrome bugs: support.google.com/chrome/answer/95315?hl=en Or report them against Chromium at code.google.com/p/chromium/issues/list
  • httpete
    httpete almost 9 years
    We had the exact same thing. Chrome tries to focus the fieldset. I just changed to <div> instead and it works.
  • Clément Prévost
    Clément Prévost over 8 years
    Same thing here, but I'll juste wait for chrome to solve this issue.
  • rpearce
    rpearce almost 8 years
    This was insanely helpful and a good brute force way of identifying it.
  • Native Coder
    Native Coder about 7 years
    This isn't a "fix" if you need client-side form validation for UX. Sure, you should be validating server-side anyway. But it really helps if the client knows exactly what's missing before the form will submit.
  • f4r4
    f4r4 almost 7 years
    This isn't a fix
  • Pete
    Pete over 2 years
    This was so helpful, I could not find where this error was coming from for the life of me!