2

i have a small question. How do i make the raty rattings become validated in the form?

Because when i uses this code

$('#rating-webratting').raty({
                    hints       : ['1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars'],
                    scoreName   : 'rating-webratting',
                    path        : 'img/',
                    starOn      : 'star_on.png',
                    starOff     : 'star_off.png'
                });

on this div

<div id="rating-webratting"></div>

When the pages load it will create this html codes inside the div

<img title="1 Star" alt="1" src="img/star_off.png">&nbsp;
<img title="2 Stars" alt="2" src="img/star_off.png">&nbsp;
<img title="3 Stars" alt="3" src="img/star_off.png">&nbsp;
<img title="4 Stars" alt="4" src="img/star_off.png">&nbsp;
<img title="5 Stars" alt="5" src="img/star_off.png">
<input name="rating-webratting" type="hidden">

But i could not add the class="required" into the input field because its generated by the script itself.

Can anyone please advise on how to do that for the jquery validation?

i have tried the addMethod but i cant add in the class into it.

Eugene Tang
  • 83
  • 2
  • 8
  • can you please tell me how did you solve this...I am not able to understand where to add this.. Is it in document.ready function ? – Freaky Thommi Jul 01 '14 at 13:44

2 Answers2

2

You shouldn't add the required class but the attribute thus:

$('input[name="rating-webrating"]').attr('required', true);

Since validate also ignores hidden fields by default you should also set the ignore option to an empty array like this:

$('form').validate({
  ignore: []
})
mhmhmhmh
  • 434
  • 1
  • 5
  • 13
1

After the input field has been generated you can select it using the attribute selector then add the class

$('input[name="rating-webratting"]').addClass('required');
wirey00
  • 33,517
  • 7
  • 54
  • 65