Closed (fixed)
Project:
Flag
Version:
7.x-2.0-beta6
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
8 Apr 2012 at 21:28 UTC
Updated:
25 Dec 2012 at 22:10 UTC
Hi,
I'm not a programmer, so I'm not very good with PHP. I've written the following code, but each time something is flagged or unflagged, a new line of text is created instead of updating the pre-existing one.
<div class="flag-likes-counter">
<?php
$flag = flag_get_flag('likes') or die('no "likes" flag');
print $flag->get_count($content_id);
print " people like this.";
?>
</div>So every time the "Like / Unlike" link is clicked, I get a new line of text generated (like this):
1 people like this
0 people like this
1 people like this
etc.
How do I make it so only the counter itself is updated and I don't get additional lines of text?
Thanks.
Comments
Comment #1
walker2238 commentedI'm also experiencing this behaviour. I think it has something to do with flags javascript... Instead of replacing the text it just appends more text for each click.
Comment #2
walker2238 commentedComment #3
walker2238 commentedCan anyone confirm this bug or is it just Po3t and myself?
Comment #4
quicksketchIt's not a bug if it's only started happening after doing some custom coding or theming. Most likely the output is missing a required wrapper with a class name on it that Flag uses for identification.
Comment #5
walker2238 commentedI'm using the default template and haven't used anything in regards to the flag API.
Here's the output of my markup... I'm quite confused in regards to this issue.
Comment #6
walker2238 commentedJust to clarify... I'm not saying you're wrong... I assume that you're right because the count (Using tokens) is working when in the title attribute but outside that it only appends itself to the current number.
Comment #7
quicksketchAh sorry @walker2238, I thought you were doing custom coding like @Po3t (in the original issue). What's the configuration for the label of your flag? Maybe I'll be able to reproduce it with enough info.
Comment #8
walker2238 commentedThat's ok, the only "custom coding" I've done was to move the $link_title variable outside the title attribute. I moved it beside the link because using it the title attribute would produce the desired results. Which seemed odd.
What do you mean by label? The flag export?
Hmmm... what else did I do... I did remove the flag.css in my themes .info. But I assume that shouldn't be an issue. I've also yet to style the flag links myself (Currently trying to solve this issue beforehand).
I also have the rate module installed but not currently outputting anything from that module.
I do have a few custom module but nothing with JS and my html is valid.
Token module version is 7.x-1.0-rc1.
To produce what I'm experiencing open the flag template and move $link_title outside the link.
Also might as well point out that though I'm using my own custom theme I've tested and experienced the same result when switching over to the Bartik 7.10 theme.
Comment #9
dagomar commentedI had the same issue in my drupal 6 installation. I know now why this is happening. You are placing your custom piece of code outside the flag span. So the javascript will not know what piece to update. Try something like this:
Comment #10
joachim commentedLooks like this was resolved.