Closed (outdated)
Project:
Rate
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 Mar 2014 at 20:37 UTC
Updated:
18 Sep 2025 at 13:35 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
almc commentedAgree, this is a serious issue in this new version 1.7 of the module: the widget inserted using the Rate native function rate_generate_widget doesn't work any longer. For this reason for now I would have to resort back to the previous version of Rate where it worked well.
Comment #2
rjacobs commentedHumm, yes, I can also confirm that this appears to be something introduced in 7.x-1.7. Thankfully downgrading seems to be trivial given that 1.7 did not introduce any schema changes or anything like that. It would be interesting to see which commit this relates to.
Also, I'm changing the version as bugs should probably always be reported against dev (currently 7.x-1.7, 7.x-1.x and HEAD are the same commit in the repository).
Comment #3
rjacobs commentedOk, this seem to have been introduced in #1676746: Addtional Classes and more unique ID.
The commit from that issue appears to alter the widget id to ensure it is unique. This makes good sense but it appears fix was incomplete in implementation. Though it ensures that widget ids are unique it may not have ensured the AHAH js logic is also able to find those new ids (meaning the click gets processed, but the AHAH logic does not replace the widget with updated info). I'm just spit-balling here, but a preliminary analysis seems to point to this general conclusion.
Revering the commit from that issue solves the problem without rolling-back all the way to 7.x-1.6.
I'm marking a relationship between these issues and will also post a note in that related (closed) issue. Maybe someone involved in that previous issue will be able to comment.
Comment #4
sjancich commentedI ran into this bug as well. I have placed three (different) widgets on my page via panels. It looks to me like the failure is in line 40 of rate.js:
In my case, my widgets had IDs like ".rate-node-143-1-1--2", but the classes looked like ".rate-node-143-1-1". So, my widget var was empty. Thus, later in the script, when it came time to replace the widget object with what was returned via rate_vote_ahah(), it failed. So, even though the vote was correctly recorded, the UI didn't update to give feedback to the user.
I edited rate.js to fetch all widgets with the ID in question (not class):
That gave me the correct object, and widget.before() and widget.remove() were able to run.
I don't really understand the implications of making this change, though. I ran a quick test by adding the same widget twice to my panel -- with my change, everything still works. Both widgets are updated when a user clicks on one to vote. And the IDs seem to be unique between the two copies.
Attaching a patch with my change...
Comment #5
rjacobs commentedI've finally had a chance to look at this more and review. From what I can see there are couple key revelations here:
Alright, so if we assume that the two points above are the way things should be (extra attention may be needed on these points, but that might be best in separate issues), it seems like we just need to be sure that the extra appended number on the widget ID (if applied) is ignored by the javascript. I think sjancich suggestion would do this (pseudo patch for rate.js ~line 40):
but isn't that just the same as commenting out the
widget = $('.' + widget.attr('id'));line altogether given that all widget ids are now unique?Perhaps instead we need to just to somewhat "cleanse" the id of any appended bits... something like (pseudo patch):
Though I suppose this could still cause problems if the same widget is used twice on the same page (the widget var at the start of Drupal.rateVote() might not represent the widget var that just received a click event.
Comment #6
rjacobs commentedMoving back to "active" and I think we need some more confirmation about why the javascript is comparing the ID to the class for each widget before this could be solved.
Comment #7
rjacobs commentedI tested this some more, and I think my alternate suggestion from comment #5 appears correct. I tested this with a few cases, including one where the exact same widget was manually inserted twice on a page, and all works as expected.
I see now that looking-up all widgets with a class that matches the id does make sense. This will ensure that multiple matching widgets will get an AHAH update if either of them is clicked. As noted earlier, that look-up process just needs to ignore any numbers appended to the ID by drupal_html_id()... which is what this fix does.
Patch attached. I'm hoping someone can review.
Comment #8
rjacobs commentedNo testers? I'm actually surprised that this is not causing more of a fuss given that this bug cripples all widgets that are built programmatically (via rate_generate_widget()).
According to the stats many thousands of people have already upgraded to 1.7 and I can't imagine that all of them are only using the GUI?
Comment #9
jvsteiner commentedThis seems to be related to the thing I reported here:
https://drupal.org/node/2266371
I made the changes in #5 and it's working for me in dev and production behind nginx
Comment #10
almc commentedCan't test it now as had to rollback to the previous version of Rate and now in a freeze state, would certainly test when attempt the next upgrade.
Comment #11
frobI applied the patch manually since it is only a few lines. It works now, tested before and it was broken.
RTBC
Comment #12
Fidelix commentedI tested patch in #7 and I can confirm it fixes the issue.
Comment #13
klase commentedI experienced the same issues as discussed herein and that seem to have led up to @rjacobs patch #7 albeit when rendering a widget in a view (that uses contextual filters to grab NID from URL) that is rendered on the content type that I had the widget enabled on (however "Do not add automatically" setting on). It could not find that particular widget in the JS due to the ID being of "wrong format" as described above.
However, by using the latest DEV version the problem went way, so is this committed? I see some changes in the JS of the handling of "widget" and "ids" between 1.7 and current DEV (which is "7.x-1.6+3-dev" according to info file).
Comment #14
quotesbro commented#7 fixed the issue for me.
@klase, 7.x-1.6+3-dev doesn't include 7.x-1.7 commits. In fact 7.x-1.7 is the latest version at this moment.
Comment #15
jonraedeke commentedRTBC based on #11, #14 and me.
Comment #16
jOksanen commentedI had another issue with it where on comments it made a JS error. Continued the existing patch with js on line 8.
+ if (typeof widget.attr('id') != 'undefined') {
}
Comment #17
chrisfromredfinPatch in #16 works for me, using Drupal Commons.
Comment #18
jOksanen commentedMarking RTBC because of the last comment.
Comment #19
frob@jOksanen, you should leave it up to another to RTBC your own patches.
Comment #20
luke_nuke commentedI made almost the same patch before I found this issue. RTBC
Comment #21
luke_nuke commentedOops, my mistake, I though somehow that #7 is the last patch, carry on.
Comment #22
ademarco commented#16 works well for me.
Comment #23
ivnishDrupal 7 is EOL. Issue will be closed, but patches are still here