0
<input id="j_id0:mainFormId:selected:selectedProductsDiv:3:quantityId" name="j_id0:mainFormId:selected:selectedProductsDiv:3:quantityId" type="text">

How do I attach jquery validator rule for the above field? All the examples are showing that we need to simply put the name attribute but in my case the name attribute keeps changing but it always ends with quantityId..

        j$('form[id$="mainFormId"]').validate({
            rules: {
                $quantityId : "required"
            }

        });

Any suggestions?

1
  • can use addMethod and use the method name as a class also Commented Jul 27, 2015 at 20:11

1 Answer 1

1

You can build the rules with code:

var rules = {};
$("form[id$=mainformId] input[name$=quantityId]").each(function() {
    rules[this.name] = "required";
});
$('form[id$="mainFormId"]').validate({
    rules: rules
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.