“Invalid form control” only in Google Chrome

前端 未结 13 1530
感情败类
感情败类 2020-11-29 03:32

The code below works well in Safari but in Chrome and Firefox the form will not submit. Chrome console logs the error An invalid form control with name=\'\' is not fo

相关标签:
13条回答
  • 2020-11-29 04:07

    I got this error message when I entered a number (999999) that was out of the range I'd set for the form.

    <input type="number" ng-model="clipInMovieModel" id="clipInMovie" min="1" max="10000">
    
    0 讨论(0)
  • 2020-11-29 04:08

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

    <form>
      <div style="display: none;">
        <input name="test" type="text" required/>
      </div>
    
      <input type="submit"/>
    </form>
    

    solution to this problem will depend on how the site should work

    for example if you don't want the form to submit unless this field is required you should disable the submit button

    so the js code to show the div should enable the submit button as well

    you can hide the button too (should be disabled and hidden because if it's hidden but not disabled the user can submit the form with others way like press enter in any other field but if the button is disabled this won't happen

    if you want the form to submit if the div is hidden you should disable any required input inside it and enable the inputs while you are showing the div

    if someone need the codes to do so you should tell me exactly what you need

    0 讨论(0)
  • 2020-11-29 04:08

    I had the error:

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

    This was happening because I was not using the required field correctly, which enabled and disabled when clicking on a checkbok. The solution was to remove the required attribute whenever the checkbok was not marked and mark it as required when the checkbox was marked.

    var telefono = document.getElementById("telefono");  
    telefono.removeAttribute("required");
    
    0 讨论(0)
  • 2020-11-29 04:10

    replace required by required="required"

    0 讨论(0)
  • 2020-11-29 04:14

    Chrome wants to focus on a control that is required but still empty so that it can pop up the message 'Please fill out this field'. However, if the control is hidden at the point that Chrome wants to pop up the message, that is at the time of form submission, Chrome can't focus on the control because it is hidden, therefore the form won't submit.

    So, to get around the problem, when a control is hidden by javascript, we also must remove the 'required' attribute from that control.

    0 讨论(0)
  • 2020-11-29 04:14
    $("...").attr("required"); and $("...").removeAttr("required"); 
    

    didn't work for me until I putted all my jQuery code between that:

    $(document).ready(function() {
        //jQuery code goes here
    });
    
    0 讨论(0)
提交回复
热议问题