with fix: multiple ratings with radios of same name but in different forms on same page don't work
| Project: | Star Rating Plugin |
| Version: | 2.0.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
when you have multiple forms in a page, each with same ratings inclusive the "name" attribute of the radios, then this plugin treats them as a single rating and mixes up the stars.
e.g.:
<form id="form1" name="form1">
<input type="radio" name="myrating" value="1">
<input type="radio" name="myrating" value="2">
</form>
<form id="form2" name="form2">
<input type="radio" name="myrating" value="1">
<input type="radio" name="myrating" value="2">
</form>and:
$('form#form1 input[@type=radio].star').rating();
$('form#form2 input[@type=radio].star').rating();Doesn't work.
Reason is that the index in the table of stars is only indexed by the name attribute of the radio buttons, in this case 'myrating', and that mixes the two ratings up.
My fix proposal is on line 84, to change the "this.name" to a combination of the form's name attribute (which should be unique) and the radio's name attribute:
So line 84:
// grouping:
var n = this.name; becomes:
// grouping:
var n = $(this).parents('form').attr('name') + '___' + this.name; //changed, was: var n = this.name;Patch-file towards current version is enclosed. Modification released as public, so it matches any license.
| Attachment | Size |
|---|---|
| star-rating.patch | 796 bytes |

Comments
#1
#2
My previous fix was fine on browser, but the name of the hidden field became prefixed too, so the server-side POST variable name was wrong. Here the fix for that:
Line 96: change:
$.rating.groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');to:
$.rating.groups[n].valueElem = $('<input type="hidden" name="' + this.name + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>'); // changed: name="n" --> name="this.name"....New patch file with both fixes attached.