Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery validation against dynamic fields
    primarykey
    data
    text
    <p>I'm using jQuery's validation plugin and looking to validate many dynamically added text fields such that their summation is checked against a separate <em>total</em> field. </p> <p>I've written my own validation methods in the past, but only simple ones that take on the basic regex structure that is easy to reproduce from the additional-methods.js file.</p> <p>Specifically, the jQuery website gives a simple example of using the <a href="http://docs.jquery.com/Plugins/Validation/Validator/addMethod" rel="nofollow noreferrer">addMethod() function</a> to do something quite similar:</p> <pre><code>jQuery.validator.addMethod("math", function(value, element, params) { return this.optional(element) || value == params[0] + params[1]; }, jQuery.format("Please enter the correct value for {0} + {1}")); </code></pre> <p>The implementation of the params parameter is more-or-less poorly documented. I was able to find how to pass content into params in <a href="https://stackoverflow.com/questions/1366858/jquery-validation-plugin-custom-method-multiple-parameters">a seperate stackoverflow thread</a>. However, the array passed into params in that example is static. The array I need to pass to params grows and shrinks based on dynamically added rows added at 'runtime'...</p> <p>I've uploaded a completely stripped down version <a href="http://jsfiddle.net/x7JQd/11/" rel="nofollow noreferrer">onto jsfiddle</a> for your viewing. <em>Note that the code has some comments embedded where I have questions, and also, I removed the Remove functionality, as it only adds clutter and doesn't help illustrate the point.</em></p> <p>So how can I use the jQuery validation library to ensure that dynamically added fields add to a specific total? Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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