It seems as if the rules object is never being passed to validate(). >From what I can see there are no rules when normalizeRules is being called however the elements are being called correctly.
Would I need to call the compare function in a different form? I can't see much difference on the way I create a hardcoded rule: rules: { "period_dates-0.period": { compare: ["#form_period_dates_0_start_date","#form_period_dates_0_end_date"] } } or a dynamic one: rules[rule_name] = { compare: ["#" + start_date, "#" + end_date] } Anyone done anything similar? Diego. On Dec 19, 10:00 am, dfiguero <dfigu...@gmail.com> wrote: > So far I got: > > $(function(){ > $.validator.addMethod("compare", function(value, element, param){ > Date.format = 'mmm. dd, yyyy'; > sdate = Date.fromString($(param[0]).val()); > edate = Date.fromString($(param[1]).val()); > > return (sdate.getTime() <= edate.getTime()) || this.optional > (element); > }, "End date must be later than the Start date") > > var rules = {}; > $(".repeatingformfield").each(function(){ > $(this).find(":text").each(function(n){ > if (n == 0) > rule_name = this.name; > if (n == 1) > start_date = this.id; > if (n == 2) > end_date = this.id; > }); > rules[rule_name] = { > compare: ["#" + start_date, "#" + end_date] > } > }); > > $(".tableform").validate({debug: true, options: rules}); > > }); > > But I guess my logic is not that great since the compare method > doesn't seem to be called. Perhaps the method definition does not > match the way I'm calling it but I'm not able to see that on firebug. > > Any suggestions? > > Diego. > > On Dec 18, 4:10 pm,dfiguero<dfigu...@gmail.com> wrote: > > > Thanks Jörn I'll give it a try! > > > On Dec 18, 12:17 pm, "Jörn Zaefferer" <joern.zaeffe...@googlemail.com> > > wrote: > > > > You could generate the rules object. > > > > var rules = {}; > > > $(":input[name*=date-start"]).each(function() { > > > rules[this.name] = { ... }}); > > > > $("...").validate({options:rules}); > > > > Jörn > > > > On Thu, Dec 18, 2008 at 3:01 PM,dfiguero<dfigu...@gmail.com> wrote: > > > > > Hi, > > > > > I'm trying to validate a form with a dynamic date fields. Something > > > > like: > > > > > <tr id="period1" class="someclass"> > > > > <td> > > > > <input type="text" name="date-1-start" id="date_1-start" > > > > value="Mar. 29, 2008" /> > > > > <input type="text" name="date-1-end" id="date_1-end" value="Mar. > > > > 29, 2008" /> > > > > </td> > > > > </tr> > > > > <tr id="period2" class="someclass"> > > > > <td> > > > > <input type="text" name="date-2-start" id="date_2-start" > > > > value="Jun. 02, 2010" /> > > > > <input type="text" name="date-2-end" id="date_2-end" value="Jun. > > > > 02, 2010" /> > > > > </td> > > > > </tr> > > > > ... > > > > <tr id="period3" class="someclass"> > > > > <td> > > > > <input type="text" name="date-n-start" id="date_n-start" > > > > value="aaa. 99, 9999" /> > > > > <input type="text" name="date-n-end" id="date_n-end" value="aaa. > > > > 99, 9999" /> > > > > </td> > > > > </tr> > > > > > I got my validation rules working but only if I hardcode each of the > > > > input's names: > > > > > $("form").validate({ > > > > rules: { > > > > "date-1-start": compare ["#date_1-start","#date_1-end"], > > > > "date-2-start": compare ["#date_2-start","#date_2-end"], > > > > ... > > > > "date-n-start": compare ["#date_n-start","#date_n-end"] > > > > } > > > > }); > > > > > Would there be a way to dynamically generate the rules? Something > > > > like: > > > > > $("form").validate({ > > > > rules: { > > > > $(":input[name*=date-start"]): compare [$(":input[name*=date- > > > > start"]),$(":input[name*=date-end"])], > > > > } > > > > }); > > > > > I know I could perhaps do this by adding classes to the input fields > > > > but I would prefer avoiding that option. > > > > > Thanks > >