7

I'm using asp.net mvc 3, and I have a scenario like the one in this post JQuery Validate multiple fields with one error. I'm using the IClientValidatable since I had to create a custom validator for my scenario. But if I apply the validator to each of the properties, I will get 3 times the error message. So I know you can use groups to tell the validator to group messages for multiple fields, and I couldn't find an option to do it from C#, so I tried to do something like this:

$("#frmUser").validate({
    groups: {
        DateofBirth : "Year Month Day"
    }
});

but the whole validation stops working, so I have the feeling that line of code overrides whatever the unobtrusive code generates. So I'm wondering if there's a way to set groups in the
validator.unobtrusive.adapters.add or validator.addMethod methods. Thanks

Community
  • 1
  • 1
oz.
  • 2,153
  • 3
  • 16
  • 15

2 Answers2

1

Something like this could help: MVC3 unobtrusive validation group of inputs

Community
  • 1
  • 1
Priyank
  • 10,503
  • 2
  • 27
  • 25
  • 3
    Thanks for the answer. That code is what I have, but still have the problem. The work-around I have so far is just to apply the attribute to just one of the properties, so I have to wait for the user to try to submit to clear the message and what I'm trying to achieve is that as soon as the user changes the value of any of the dropdowns, the validation kicks. But if I apply the attribute to only one property, it will only kick when that value is changed, not all 3. – oz. May 07 '11 at 15:51
0

Have you already tried :

$.validator.setDefaults({ groups: { DateofBirth : "Year Month Day" } });

Francesco Abbruzzese
  • 4,139
  • 1
  • 17
  • 18
  • This does not work; I believe unobtrusive validation initializes the object and does not look at the defaults specified – codechurn Jan 29 '15 at 18:16