Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display jQuery validator error messages for a dynamic form without duplicating same type of messages
    text
    copied!<p>I have a table which represents an input form for an invoice, the amount of rows is dynamic, depending on how many products the user puts into the invoice,</p> <p>the amount of inputfields per row is always the same and they all represent the same things, thus have the same validation rules.</p> <pre><code>&lt;form id="myform" name="myform" action="" method=""&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="text" name="amount_id1" id="amount_id1" value=""/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" name="price_id1" id="amount_id1" value=""/&gt; &lt;/td&gt; .... &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="text" name="amount_id2" id="amount_id2" value=""/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" name="price_id2" id="price_id2" value=""/&gt; &lt;/td&gt; ..... &lt;/tr&gt; .... &lt;/table&gt; &lt;/form&gt; </code></pre> <p>I'm using the jQuery validation plugin: <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">validation plugin</a></p> <p>Now what I want to happen is, I want to wrap all the errors into ONE container, because displaying them next to each inputfield is messy as hell.</p> <p>I know this can be achieved with the wrapper settings, and the errorLabelContainer </p> <p>But, I don't want to display duplicate messages:<br> there really is no use to display "amount needs to be a positive number" x10 times for each and all 10 fields where the user made a mistake...<br> So what I want is, per kind of input field (be it amount, price, discount, vat, or whatever) if there is one wrong input, I want to display 1 error message for that kind of mistake<br> example:<br> amount has required and digits as class rules.<br> If the user forgets to enter the amount in different places, I want 1 message in the errorcontainer saying: "amount fields are mandatory" if next to that, he enters a "char or something non-digit" into an amount field, I want an additional errormessage saying, "amount fields are supposed to be digits only"'</p> <p>Another way to say things is:<br> if the message is already displayed, don't display it,<br> if it isn't, display it.</p> <p>To help show the user which fields aren't valid, I just use the highlight, unhighlight settings, adding a class to the field in question which gives it a red border. This works like a charm.</p> <p>I've tried using showErrors, invalidHandler, errorPlacement, but I can't get things to work. not even close. There is no array/object which contains current invalid formelements for the entire form. There is however errorMap and errorList which contain the errors of the CURRENT validation phase. meaning half the time it only contains errors for one field due to focus/blur effects. Yes I know disabling all options so the validation only get's triggered when the form is trying to be submit, would mean the errorMap/errorList would then always contain all errors for the entire form. But this isn't really an option imo/myBoss'sOpinion. I tried digging in the validator properties, in the validator source, looking for something that could help, but I can't seem to find anything..</p> <p>I hope I explained things well enough for someone to help me on this, because I've been breaking my head for a while on this one.</p> <p>Any help/suggestions/idea's are welcome :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload