I noticed it's possible to change your vote between ThumbsUp and ThumbsDown. Is it possible to undo your vote?

Comments

eliza411’s picture

I'm seeking clarification: A user cannot cancel his or her vote in this or earlier versions?

ezra-g’s picture

Title: Thumbs Up/ Down or Reset (Undo Vote) » Undo/Cancel a vote

@eliza411, I believe that is correct.

Updating the issue title to clarify the feature requested here.

I'm working on a project that calls for this feature initially in the D6 version of Rate, but would likely need it in the D7 version eventually as well. I may be filing a patch ;).

tomogden’s picture

My sites need this function as well. Good UI generally requires the user have a way to "undo" an action. There's currently no alternative to clicking a simple "Like" button. You can't take back that vote.

For Up/Down and Like widgets, the behavior seems simple: Clicking once sets the vote. Clicking again on the SAME button unsets the vote. Is that what you were thinking?

Good luck with this.

mmilo’s picture

This can be done from the theme/module layer using hook_rate_vote_alter(), but the cache for the voting results won't be rebuilt.

Might want to follow #382866: provide script and documentation to rebuild the votingapi cache as well.

ezra-g’s picture

ezra-g’s picture

Issue tags: +commonslove

Adding the commonslove tag.

patrick.thurmond@gmail.com’s picture

Assigned: Unassigned » patrick.thurmond@gmail.com

I am looking into getting this implemented. I am starting in the 7.x-1.x branch since the 2.x branch is not really functional yet.

ezra-g’s picture

It seems like the 2.x branch is the active development branch, so I'd recommend going with that branch. Rate maintainers, feel free to let us know if that's not correct.

leschekfm’s picture

I did implement this in a custom module using hook_rate_vote_alter(). This worked flawlessly with rate-7.x-1.3 .
The snippet below alters the behavior of the rate widget to delete the previous given vote if you click on a rate button you had clicked anytime before.
Do note that this will probably cause problems with the Anonymous vote rollover, which we didn't need.

/**
 * Implements hook_rate_vote_alter().
 *
 * We check if there are already votes from the logged in user and if so 
 * delete them.
 */
function rate_extras_rate_vote_alter($votes, $context) {
  global $user;
  $to_delete = array();

  // get previous votes of this user
  $votes['uid'] = $user->uid;
  foreach (votingapi_select_votes($votes) as $vote) {
    $to_delete[] = $vote;
  }

  // delete previous votes
  if (!empty($to_delete)) {
    votingapi_delete_votes($to_delete);
    votingapi_recalculate_results($votes['entity_type'], $votes['entity_id']);
    // prevent the vote from being saved again in rate_save_vote
    $context['save'] = 0;
  }

  return;
}
patrick.thurmond@gmail.com’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

I have added the ability (per my attached patch) to undo/cancel a vote as requested in http://drupal.org/node/1185272. Specifically I added a widget specific feature that allows a second click on the same vote to undo the previously cast vote by that user.

So after applying this patch you need to go into the widget you are using. Then under "Interaction" the third question that shows up asks if the second click on a vote button should undo the previous vote. Some of the wording might feel awkward, but I think the intended functionality is clear.

Please let me know if there are any problems with it.

patrick.thurmond@gmail.com’s picture

StatusFileSize
new7.58 KB

Apparently the first patch file didn't generate properly due to an issue with viewing the repository with Git Tower while using the command line to make the patch. Here is the patch file with content.

mauritsl’s picture

Looks good, thanks! I will test this patch soon and commit if everything works fine.

Not sure why this part is needed, though..

+  if (!in_array($form_state['values']['delete_vote_on_second_click'], array('0', '1'))) {
+    form_set_error('delete_vote_on_second_click', t('Invalid option selected for deleting on second click.'));
+  }
mauritsl’s picture

Committed to 7.x. Thanks!

I've added an update hook to add the "delete_vote_on_second_click" property to existing widgets.

mauritsl’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

grn’s picture

Version: 7.x-2.x-dev » 7.x-1.5
Status: Closed (fixed) » Needs review

Hi, in wich version is this implemented?

It does not seem to work for me in 7.x-1.5. I use the vote up widget, counting the votes.

Thanks.

grn’s picture

Status: Needs review » Fixed

Sorry, it was a setting in the settings on the rate widget.

BR. GrN.dk

mauritsl’s picture

Status: Fixed » Closed (fixed)
ivnish’s picture

Assigned: patrick.thurmond@gmail.com » Unassigned
Issue summary: View changes
Issue tags: -