Which one of the following is an invalid form of the matrix project management structure

This issue occurs on Chrome if a form field fails validation, but due to the respective invalid control not being focusable the browser's attempt to display the message "Please fill out this field" next to it fails as well.

A form control may not be focusable at the time validation is triggered for several reasons. The two scenarios described below are the most prominent causes:

  • The field is irrelevant according to the current context of the business logic. In such a scenario, the respective control should be disabled or removed from the DOM or not be marked with the required attribute at that point.

  • Premature validation may occur due to a user pressing ENTER key on an input. Or a user clicking on a button/input control in the form which has not defined the type attribute of the control correctly. If the type attribute of a button is not set to button, Chrome [or any other browser for that matter] performs a validation each time the button is clicked because submit is the default value of a button's type attribute.

To solve the problem, if you have a button on your page that does something else other than submit or reset, always remember to do this: .

answered Feb 5, 2015 at 9:38

Igwe KaluIgwe Kalu

13.7k2 gold badges26 silver badges39 bronze badges

19

Adding a novalidate attribute to the form will help:


answered Mar 3, 2014 at 13:48

user2909164user2909164

4,5271 gold badge12 silver badges2 bronze badges

21

In your form, You might have hidden input having required attribute:

The form can't focus on those elements, you have to remove required from all hidden inputs, or implement a validation function in javascript to handle them if you really require a hidden input.

IgniteCoders

4,4863 gold badges43 silver badges60 bronze badges

answered Apr 22, 2014 at 9:16

Ankit SharmaAnkit Sharma

5,0262 gold badges22 silver badges28 bronze badges

7

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:

$["body"].on["submit", ".myForm", function[evt] {

    // Disable things that we don't want to validate.
    $[["input:hidden, textarea:hidden, select:hidden"]].attr["disabled", true];

    // If HTML5 Validation is available let it run. Otherwise prevent default.
    if [this.el.checkValidity && !this.el.checkValidity[]] {
        // Re-enable things that we previously disabled.
        $[["input:hidden, textarea:hidden, select:hidden"]].attr["disabled", false];
        return true;
    }
    evt.preventDefault[];

    // Re-enable things that we previously disabled.
    $[["input:hidden, textarea:hidden, select:hidden"]].attr["disabled", false];

    // Whatever other form processing stuff goes here.
}];

Also, this is possibly a duplicate of "Invalid form control" only in Google Chrome

answered Mar 31, 2014 at 4:14

Horatio AlderaanHoratio Alderaan

3,2462 gold badges22 silver badges30 bronze badges

6

In my case the problem was with the input type="radio" required being hidden with:

visibility: hidden;

This error message will also show if the required input type radio or checkbox has a display: none; CSS property.

If you want to create custom radio/checkbox inputs where they must be hidden from the UI and still keep the required attribute, you should instead use the:

opacity: 0; CSS property

answered Apr 25, 2017 at 19:45

GusGus

5,9294 gold badges32 silver badges35 bronze badges

5

None of the previous answers worked for me, and I don't have any hidden fields with the required attribute.

In my case, the problem was caused by having a and then a as its first child, which holds the with the required attribute. Removing the solved the problem. Or you can wrap your form with it; it is allowed by HTML5.

I'm on Windows 7 x64, Chrome version 43.0.2357.130 m.

answered Jul 2, 2015 at 22:42

PerePere

1,05812 silver badges20 bronze badges

10

Not only required field as mentioned in other answers. Its also caused by placing an field in a hidden

which holds an invalid value.

Consider below example,

This throws the same error. So make sure the fields inside hidden

doesnt hold any invalid value.

answered Jul 23, 2020 at 9:08

Abhinav KinagiAbhinav Kinagi

3,4131 gold badge24 silver badges42 bronze badges

3

This issue occurs when you provide style="display:none;" and required attribute to the input field, and there will be validation on submit. for example:


This issue can be resolved by removing required attribute from the input field from your HTML. If you need to add required attribute, add it dynamically. If you are using JQuery, use below code:

$["input"].prop['required',true];

If you need to remove this field dynamically,

$["input"].prop['required',false];

You can also make use of plain Javascript if you are not using JQuery:

document.getElementById['element_id'].removeAttribute['required'];

answered Apr 7 at 5:16

AyeshaAyesha

2012 silver badges7 bronze badges

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:

input[type="checkbox"] {
    visibility: hidden;
}

Simple fix was to replace it with this:

input[type="checkbox"] {
    opacity: 0;
}

answered Dec 15, 2015 at 15:52

SamSam

4,9044 gold badges28 silver badges37 bronze badges

1

For me this happens, when there's a field with pre-selected option with value of '':


    Select something
    Bar
    Baz

Unfortunately it's the only cross-browser solution for a placeholder [How do I make a placeholder for a 'select' box?].

The issue comes up on Chrome 43.0.2357.124.

answered Jun 16, 2015 at 12:26

piotr_czpiotr_cz

7,6972 gold badges30 silver badges24 bronze badges

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.

$['form select'].each[function[i]{
this.addEventListener['invalid', function[e]{            
        var _s2Id = 's2id_'+e.target.id; //s2 autosuggest html ul li element id
        var _posS2 = $['#'+_s2Id].position[];
        //get the current position of respective select2
        $['#'+_s2Id+' ul'].addClass['_invalid']; //add this class with border:1px solid red;
        //this will reposition the hidden select2 just behind the actual select2 autosuggest field with z-index = -1
        $['#'+e.target.id].attr['style','display:block !important;position:absolute;z-index:-1;top:'+[_posS2.top-$['#'+_s2Id].outerHeight[]-24]+'px;left:'+[_posS2.left-[$['#'+_s2Id].width[]/2]]+'px;'];
        /*
        //Adjust the left and top position accordingly 
        */
        //remove invalid class after 3 seconds
        setTimeout[function[]{
            $['#'+_s2Id+' ul'].removeClass['_invalid'];
        },3000];            
        return true;
}, false];          
}];

answered Feb 18, 2016 at 1:11

SudarPSudarP

87610 silver badges12 bronze badges

It can be that you have hidden [display: none] fields with the required attribute.

Please check all required fields are visible to the user :]

answered Apr 7, 2017 at 14:47

ghurooghuroo

3082 silver badges10 bronze badges

If you have any field with required attribute which is not visible during the form submission, this error will be thrown. You just remove the required attribute when your try to hide that field. You can add the required attribute in case if you want to show the field again. By this way, your validation will not be compromised and at the same time, the error will not be thrown.

answered Aug 27, 2015 at 17:23

maniempiremaniempire

78111 silver badges12 bronze badges

1

It's weird how everyone is suggesting to remove the validation, while validation exists for a reason... Anyways, here's what you can do if you're using a custom control, and want to maintain the validation:

1st step. Remove display none from the input, so the input becomes focusable

.input[required], .textarea[required] {
    display: inline-block !important;
    height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    z-index: -1 !important;
    position: absolute !important;
}

2nd step. Add invalid event handler on the input to for specific cases if the style isn't enough

inputEl.addEventListener['invalid', function[e]{
   //if it's valid, cancel the event
   if[e.target.value] {
       e.preventDefault[];
   }
}]; 

answered Jun 22, 2020 at 12:52

Inc33Inc33

1,7001 gold badge20 silver badges25 bronze badges

1

I came here to answer that I had triggered this issue myself based on NOT closing the 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

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

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

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

answered Feb 21, 2017 at 2:08

FrankenmintFrankenmint

1,5303 gold badges17 silver badges32 bronze badges

0

Another possible cause and not covered in all previous answers when you have a normal form with required fields and you submit the form then hide it directly after submission [with javascript] giving no time for validation functionality to work.

The validation functionality will try to focus on the required field and show the error validation message but the field has already been hidden, so "An invalid form control with name='' is not focusable." appears!

Edit:

To handle this case simply add the following condition inside your submit handler

submitHandler[] {
    const form = document.body.querySelector['#formId'];

    // Fix issue with html5 validation
    if [form.checkValidity && !form.checkValidity[]] {
      return;
    }

    // Submit and hide form safely
  }

Edit: Explanation

Supposing you're hiding the form on submission, this code guarantees that the form/fields will not be hidden until form become valid. So, if a field is not valid, the browser can focus on it with no problems as this field is still displayed.

answered Oct 27, 2016 at 16:12

MouneerMouneer

12.2k2 gold badges36 silver badges45 bronze badges

0

There are many ways to fix this like

  1. Add novalidate to your form but its totally wrong as it will remove form validation which will lead to wrong information entered by the users.

  1. Use can remove the required attribute from required fields which is also wrong as it will remove form validation once again.

    Instead of this:

   Use this:

  1. Use can disable the required fields when you are not going to submit the form instead of doing some other option. This is the recommended solution in my opinion.

    like:

or disable it through javascript / jquery code dependes upon your scenario.

answered Nov 18, 2017 at 9:12

Umar AsgharUmar Asghar

3,4521 gold badge32 silver badges29 bronze badges

It will show that message if you have code like this:


  

KyleMit

35.4k61 gold badges431 silver badges624 bronze badges

answered Sep 28, 2014 at 0:22

RobertRobert

2,0342 gold badges25 silver badges38 bronze badges

4

Yea.. If a hidden form control has required field then it shows this error. One solution would be to disable this form control. This is because usually if you are hiding a form control it is because you are not concerned with its value. So this form control name value pair wont be sent while submitting the form.

answered Jun 11, 2016 at 9:49

1

You may try .removeAttribute["required"] for those elements which are hidden at the time of window load. as it is quite probable that the element in question is marked hidden due to javascript [tabbed forms]

e.g.

if[document.getElementById['hidden_field_choice_selector_parent_element'.value==true]{
    document.getElementById['hidden_field'].removeAttribute["required"];        
}

This should do the task.

It worked for me... cheers

u01jmg3

7001 gold badge13 silver badges31 bronze badges

answered Nov 20, 2014 at 16:35

There are things that still surprises me... I have a form with dynamic behaviour for two different entities. One entity requires some fields that the other don't. So, my JS code, depending on the entity, does something like: $['#periodo'].removeAttr['required']; $["#periodo-container"].hide[];

and when the user selects the other entity: $["#periodo-container"].show[]; $['#periodo'].prop['required', true];

But sometimes, when the form is submitted, the issue apppears: "An invalid form control with name=periodo'' is not focusable [i am using the same value for the id and name].

To fix this problem, you have to ensurance that the input where you are setting or removing 'required' is always visible.

So, what I did is:

$["#periodo-container"].show[]; //for making sure it is visible
$['#periodo'].removeAttr['required']; 
$["#periodo-container"].hide[]; //then hide

Thats solved my problem... unbelievable.

answered Dec 24, 2017 at 17:26

Gustavo SolerGustavo Soler

1,4692 gold badges8 silver badges6 bronze badges

In my case..

ng-show was being used.
ng-if was put in its place and fixed my error.

answered Aug 16, 2018 at 18:39

1

It happens if you hide an input element which has a required attribute.

Instead of using display:none you can use opacity: 0;

I also had to use some CSS rules [like position:absolute] to position my element perfectly.

answered Aug 16 at 21:27

Serdar D.Serdar D.

2,7711 gold badge26 silver badges19 bronze badges

For Angular use:

ng-required="boolean"

This will only apply the html5 'required' attribute if the value is true.


answered Sep 7, 2015 at 2:53

Nick TarasNick Taras

5567 silver badges13 bronze badges

I found same problem when using Angular JS. It was caused from using required together with ng-hide. When I clicked on the submit button while this element was hidden then it occurred the error An invalid form control with name='' is not focusable. finally!

For example of using ng-hide together with required:


I solved it by replacing the required with ng-pattern instead.

For example of solution:


answered Apr 27, 2018 at 14:55

Not just only when specify required, I also got this issue when using min and max e.g.


That field can be hidden and shown based on other radio value. So, for temporary solution, I removed the validation.

answered Feb 6, 2019 at 10:40

deerawandeerawan

7,5165 gold badges38 silver badges47 bronze badges

1

Its because there is a hidden input with required attribute in the form.

In my case, I had a select box and it is hidden by jquery tokenizer using inline style. If I dont select any token, browser throws the above error on form submission.

So, I fixed it using the below css technique :

  select.download_tag{
     display: block !important;//because otherwise, its throwing error An invalid form control with name='download_tag[0][]' is not focusable.
    //So, instead set opacity
    opacity: 0;
    height: 0px;

 }

answered Aug 10, 2016 at 21:54

sudipsudip

2,6591 gold badge29 silver badges40 bronze badges

For other AngularJS 1.x users out there, this error appeared because I was hiding a form control from displaying instead of removing it from the DOM entirely when I didn't need the control to be completed.

I fixed this by using ng-if instead of ng-show/ng-hide on the div containing the form control requiring validation.

Hope this helps you fellow edge case users.

answered Jul 17, 2018 at 16:41

J.D. MallenJ.D. Mallen

3,9533 gold badges22 silver badges33 bronze badges

Let me put state my case since it was different from all the above solutions. I had an html tag that wasn't closed correctly. the element was not required, but it was embedded in a hidden div

the problem in my case was with the type="datetime-local", which was -for some reason- being validated at form submission.

i changed this


into that


answered Feb 14, 2019 at 12:47

SoliQuiDSoliQuiD

1,9731 gold badge23 silver badges28 bronze badges

I have seen this question asked often and have come across this 'error' myself. There have even been links to question whether this is an actual bug in Chrome.
This is the response that occurs when one or more form input type elements are hidden and these elements have a min/max limit [or some other validation limitation] imposed.

On creation of a form, there are no values attributed to the elements, later on the element values may be filled or remain unchanged. At the time of submit, the form is parsed and any hidden elements that are outside of these validation limits will throw this 'error' into the console and the submit will fail. Since you can't access these elements [because they are hidden] this is the only response that is valid.

This isn't an actual fault nor bug. It is an indication that there are element values about to be submitted that are outside of the limits stipulated by one or more elements.

To fix this, assign a valid default value to any elements that are hidden in the form at any time before the form is submitted, then these 'errors' will never occur. It is not a bug as such, it is just forcing you into better programming habits.

NB: If you wish to set these values to something outside the validation limits then use form.addEventListener['submit', myFunction] to intercept the 'submit' event and fill in these elements in "myFunction". It seems the validation checking is performed before "myFunction[] is called.

answered Feb 28, 2019 at 6:01

KentKent

3633 silver badges5 bronze badges

What is matrix structure in project management?

A matrix organization is a work structure where team members report to multiple leaders. In a matrix organization, team members [whether remote or in-house] report to a project manager as well as their department head.

What are the three project management matrix structures?

Depending on the decision-making capacity of the project manager, a matrix structure is one of three subtypes: weak, balanced, or strong..
Weak Structure. ... .
Balanced Structure. ... .
Strong Structure..

What are the three types of matrix organizations?

There are three types of matrix organizational structures:.
Weak matrix structure. A weak matrix structure is most similar to a traditional hierarchical structured workplace. ... .
Balanced matrix structure. ... .
Strong matrix structure..

What are the 4 types of organizational structures in project management?

According to PMI, there are four basic types of organization: Functional, Matrix, Projectized, and Composite. In this article, we'll take a closer look at each of these organization types.

Bài Viết Liên Quan

Chủ Đề