jQuery star rating problem with brackets []

If you used the star rating plugin of jQuery in cakePHP, you might experienced that the hover effects are not working properly. This is because one of the class name used to identify the buttons uses the radio button name. This will be a problem in cakephp because we use brackets in names.

<input type="radio" name="data[Model][field]" class="star" />

In order to fix that, we need to remove them. Here is quick fix. Open file
jquery.rating.js
:

from (line 97):
// grouping:
  var n = this.name;

to:
// grouping:
  var real_name = this.name;
  var n = real_name.replace(/[^A-Za-z0-9_\-]/g, '-'); // remove unwanted characters

from (line 108):
$.rating.groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');

to:
$.rating.groups[n].valueElem = $('<input type="hidden" name="' + real_name + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '>');

I have reported this in the bugtracker and I hope it will be included in the next release.

Tags: , ,

4 Responses to “jQuery star rating problem with brackets []”

  1. links for 2008-07-29 « Richard@Home Says:
    [...] Promet CakePHP Source» Blog Archive » jQuery star rating problem with brackets [] Handy, I was about to implement this in a soon to be released project (tags: cakephp jquery star rating) Posted by Richard@Home Filed in 15 [...]
  2. Richard@Home Says:
    Looks like your bug report has been dealt with. I downloaded the latest version of the jquery.rating.js and it has your suggested fix in place.
  3. rchel Says:
    thanks for the update Richard!
  4. Having a problem with the names in html controls that are using brackets in CakePHP « Myles Kadusale’s Blog Says:
    [...] Having a problem with the names in html controls that are using brackets in CakePHP Some solution Click here [...]

Add Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>