0

The question seems simple but I cannot seem to find a solution on stackoverflow or any other source.

jQuery validation (unobstrusive) is perfect while managing fields.

However, can we check a collection length with it?

Using data- on the form for example?

Why

You may say OK but why don't you just check it with a javascript method?

The real thing is that I am using MVC3 custom data annotations to generate the validation code for me.

So it would be better to only have to set an attribute on the MVC model, and to let jQuery validate handle all the checkings and generate the errors messages in the error summary.


I've seen validation for:

But nothing that handles the minimum of a collection.

Is there any way to handle some kind of "collection logic?" (client side)

no field = no validation, that's the problem I have for the moment

Everything works for the server-side, but since there is no field, there's no data.

Community
  • 1
  • 1
Micaël Félix
  • 2,697
  • 5
  • 34
  • 46

1 Answers1

1

Quote OP:

"However, can we check a collection length with it? Using data- on the form for example?"

"no field = no validation, that's the problem I have for the moment"

The Unobtrusive Validation (powered by the jQuery Validate plugin) can only evaluate rules on the data from the following form elements: input (various types), select and textarea.

So if you're looking for a way to perform validation on some other kind of element, then it cannot be done with this plugin.

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • That's sad, it means we cannot use only this plugin for all kind of form validation logic. The only solution that I found would be to have a hidden field that represents the number of entries, and add data validation attributes on it so it can handle the collection length problem. – Micaël Félix Jan 07 '15 at 08:55