0

I'm using jquery validation on a form that contains a number of SELECT items. The form is dynamically generated, so I don't know ahead of time how many items there will be. All I want to do is be sure that each SELECT has a non-empty value, so giving each SELECT a required style and letting validate() do its thing is all that I need.

This is currently working nicely, except that validation failures produce the standard boring "This field is required" message. I'd like to substitute something more specific, but I can't figure out how to specify that message, such that it will be produced for all the SELECTs that need it. I suppose I could generate a string containing the messages clause for the validation handler, with one line for each SELECT, and insert it into the handler, but there has to be a more rational way to do this. Right? Any suggestions for what that might be? Thanks!

3
  • Each select gets a unique message? Or all select elements will get the same custom message? Also, please show your relevant code. Commented Dec 8, 2015 at 19:18
  • How are you generating the SELECT dynamically ???? you can generate the select like this <select id="ddlGrade" name="ddlGrade" class="form-control" data-rule-required='true' data-msg-required="Grade is required!"></select> so you need to provide (data-msg-required="Grade is required!" ) attribute. Commented Dec 8, 2015 at 19:20
  • @Lucky -- I'm generating the form with some PHP, but, in any case, the data-msg-required thing works great. If you redo this as an actual answer, I'll be happy to accept it. Thanks! Commented Dec 8, 2015 at 20:04

1 Answer 1

1

How are you generating the SELECT dynamically ???? you can generate the select like this

<select id="ddlGrade" name="ddlGrade" class="form-control" data-rule-required='true' data-msg-required="Grade is required!"></select> 

so you need to provide (data-msg-required="Grade is required!" ) attribute.

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.