Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 246
nach Avatar asked Jun 04 '15 13:06

nach


4 Answers

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.

like image 79
Doug Avatar answered Nov 14 '22 23:11

Doug


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.

like image 40
Neto Yo Avatar answered Nov 15 '22 00:11

Neto Yo


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.

like image 1
nach Avatar answered Nov 14 '22 22:11

nach


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

like image 1
Sjoerd Avatar answered Nov 15 '22 00:11

Sjoerd