0

Answer It turned out to be very simple. Some time after I wrote the code, another developer added a form to the navbar for logging in. At this point, the code...

$('form').validate().showErrors({"Amount":"Bleah"})

...now affected two forms. As the log-in form was first in the HTML, I guess that got handled first, and threw the exception. By changing the code to...

$('#donateForm').validate().showErrors({"Amount":"Bleah"})

...it works fine. Thanks to all for the replies.


I'm having a problem adding errors to a form using jQuery.validate. If I load a page with the following...

<form id="donateForm">
  <div>
    <div class="form-group row">
      <label for="Amount" class="col-lg-2 col-form-label">Amount</label>
      <div class="col-lg-10 input-group">
        <div class="input-group-prepend">
          <span class="input-group-text">
            <i class="fa fa-pound-sign"></i>
          </span>
        </div>
        <input type="text" id="Amount" name="Amount" class="form-control" value="" />
      </div>
    </div>
  </div>
</form>

...and then call the following from the console...

$('form').validate().showErrors({"Amount":"Bleah"})

...then I get the following error...

Uncaught TypeError: Cannot read property 'type' of undefined
at $.validator.highlight (jquery.validate.js:344) at $.validator.defaultShowErrors (jquery.validate.js:912)
at $.validator.showErrors (jquery.validate.js:546)
at anonymous:1:22

I had a look at line 546 of jQuery.validate.js, and it was this...

this.defaultShowErrors();

...inside the showErrors function. This doesn't mean anything to me, but might help someone else work out what's going wrong.

Anyone any ideas? I realise I haven't given you much, but as showErrors is a function built in to jQuery.validate, I'm not sure what else is relevant.

Avrohom Yisroel
  • 5,898
  • 6
  • 37
  • 72

0 Answers0