# "Unvote" a poll

**URL:** https://meta.discourse.org/t/unvote-a-poll/50476
**Category:** Feature
**Created:** [September 22, 2016, 7:08am UTC](https://meta.discourse.org/t/unvote-a-poll/50476 "2016-09-22T07:08:59Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![MiguelAngelLV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/miguelangellv/32/121518_2.png) [@MiguelAngelLV](https://meta.discourse.org/u/MiguelAngelLV)
#### Post date: [September 22, 2016, 7:09am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/1 "2016-09-22T07:09:00Z")

</div>

Is posible remove a vote from a poll?

I only can change my vote, but I can’t “cancel”

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [September 22, 2016, 8:37am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/2 "2016-09-22T08:37:52Z")

</div>

Not sure if that is possible at the current time.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [September 22, 2016, 10:43am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/3 "2016-09-22T10:43:58Z")

</div>

Nope, there’s currently no way to “unvote” on a poll. Added to my ✏

---

<div class="post-metadata">

### Author: ![anon23840344](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@anon23840344](https://meta.discourse.org/u/anon23840344)
#### Post date: [October 3, 2020, 3:53pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/4 "2020-10-03T15:53:51Z")

</div>

This needs to be implemented, please! I was just trying to highlight text of a poll to copy/paste (I don’t see why that’s not allowed, by the way), and now I’ve mistakenly voted in a poll.

---

<div class="post-metadata">

### Author: ![anon89147131](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@anon89147131](https://meta.discourse.org/u/anon89147131)
#### Post date: [October 3, 2020, 5:22pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/5 "2020-10-03T17:22:59Z")

</div>

You can do that, either revote or in some cases there is a remove vote button, not sure if it is a plugin or now available.

---

<div class="post-metadata">

### Author: ![anon23840344](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@anon23840344](https://meta.discourse.org/u/anon23840344)
#### Post date: [October 3, 2020, 5:35pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/6 "2020-10-03T17:35:36Z")

</div>

I don’t wish to vote for a different option. I was abstaining from the vote. I only wished to click-drag and highlight the text to copy and paste it.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [September 25, 2021, 1:10pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/7 "2021-09-25T13:10:15Z")

</div>

Hi, any news about this? I got a complaint from one of my users who can’t cancel his public vote on a poll.

Similar topic here: [Ability to remove my choice in a poll](https://meta.discourse.org/t/ability-to-remove-my-choice-in-a-poll/53642)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 28, 2021, 6:14am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/8 "2021-09-28T06:14:54Z")

</div>

I still don’t think there is a way, @zogstrip possibly worth assigning this out cause we have meant to do this for a while.

_Poll ([view on site](https://meta.discourse.org/t/unvote-a-poll/50476/8))_

Perhaps the first thing here [@designers](https://meta.discourse.org/groups/designers) is to figure out if we want to allow this unconditionally, or only on specific polls?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [September 28, 2021, 6:40am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/9 "2021-09-28T06:40:25Z")

</div>

I agree, it’s about time.

@nbianca can you add this to your list?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 28, 2021, 6:42am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/10 "2021-09-28T06:42:31Z")

</div>

Oh I guess we would only be touching this screen:

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/2/4299bc2b74a58658b800f7fa28191eaae47e4cec.png)

Add a button after “Show results” for “Remove Vote”.

Would not impact how polls render you have to dig in to get the options.

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [September 28, 2021, 8:57am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/11 "2021-09-28T08:57:16Z")

</div>

I use polls heavily in my plugin to capture structured user input so this would be a great change for me.

Can I ask that we still fire the vote event when votes are removed so that I know there has been a change?

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [September 28, 2021, 2:35pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/13 "2021-09-28T14:35:51Z")

</div>

I implemented the unvote functionality in:

[https://github.com/discourse/discourse/pull/14459](https://github.com/discourse/discourse/pull/14459)

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [October 5, 2021, 4:23pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/14 "2021-10-05T16:23:08Z")

</div>

Hi, I’ve just pulled down the latest build to my dev environment to test this and I’ve noticed a small, perhaps non-intentional change.

It’s a small change, but it’s significant to me due to the quirky way I use polls.

Previously, if there were no votes in the poll, the “Show results” button would be disabled. That made sense, there are no results to see so the “Show results” button shouldn’t be pressable. It looked like this…

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/2/d2cc2ea590380ea8b3fe7c7a893c89f7ebd9401d.png)  
_Notice there have been no votes and the “Show results” button is disabled_

In the new “Unvote” build _it appears_ that the “Show Results” button is always enabled whether there have been votes or not.

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/f/1fb08db577713dc361f6d3158f2806d9122aab8a.png)  
_Notice there have been no votes cast but the “Show results” button is enabled_

Some questions: Is this the case? Was this intentional or an oversight? Will you be changing it back?

If it’s staying the way it is, then I’ll try another way to achieve my desired outcome.

Either way thanks for the unvote feature which seems to work very well!

> **Background**
>
> ## Background…
> 
> Why is this an issue to me? I use polls to capture the input from (mostly) individual users. i.e. a poll allows me to ask specific questions of an individual user in a specific context. There is seldom more than one vote in a poll but they make gathering structured data very easy.
> 
> In my plugin, a topic can feature many polls and these polls can feature lots of options which means a lot of scrolling. To make it easier for the users to navigate, once they have voted, a theme component I wrote removes the other options from the poll UI leaving only the option they selected.
> 
> To remove these options, my theme component targets an **enabled** “Show results” button and “clicks” it, once the results are shown, any options that have no votes are removed.
> 
> It ends up looking like this.
> 
> ![image](https://global.discourse-cdn.com/meta/original/3X/0/0/00d29d5509a79647fb90c33195f8dc7d7358f46a.png)
> 
> At the moment, because the “Show results” button is enabled by default, my code clicks it and as there haven’t been any votes, all of the options are removed and it looks like this…
> 
> ![image](https://global.discourse-cdn.com/meta/original/3X/4/1/41266229a12f4d0c37677bcd9e9c3da1124f3f83.png)

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [October 5, 2021, 5:17pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/15 "2021-10-05T17:17:39Z")

</div>

I’ve just looked at how I might approach this differently now that the results are always shown and have realised that I can accomplish what I want in a far simpler way.

So please leave it as it is! LOL 🙃

I simply target chosen (or not `.chosen`) result elements and set them to not display.

```plaintext
div.poll div.poll-container ul.results > li:not(.chosen) {
    display: none;
}

```

When I wrote my code a couple of years ago, I either didn’t notice the `.chosen` class or it’s a recent addition?

Either way, what I had was significantly over-engineered (polling Javascript!) as this seems to do what I need.

![6451AF5C-2351-49E0-9A1F-C6C0A3D0D5E9](https://global.discourse-cdn.com/meta/original/3X/a/b/ab4c4b2f5e2f99d3c764085ee46cc463684f9803.gif)

Thanks again.

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [October 6, 2021, 12:20pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/16 "2021-10-06T12:20:00Z")

</div>

Oh, that’s my bad. I just reimplemented that and it will be available soon:

[https://github.com/discourse/discourse/pull/14528](https://github.com/discourse/discourse/pull/14528)

> [@bletch](#):
>
> When I wrote my code a couple of years ago, I either didn’t notice the `.chosen` class or it’s a recent addition?

I think it has been like this for a while.

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [October 6, 2021, 8:17pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/18 "2021-10-06T20:17:23Z")

</div>

Just testing it now @nbianca and the button now seems to work like before. Thx!

One other question, I use the `DiscoursePoll::Poll.vote` method to automatically vote in polls. I’ve run into some issues in my code. Can I confirm that during the refactoring of the poll code, you changed the method signature?

My code _was_ assuming a signature of:

```ruby
def vote(post_id, poll_name, options, user)

```

and it now appears that after your changes the signature is

```ruby
def self.vote(user, post_id, poll_name, options)

```

i.e. the `user` parameter was 4th but it is now 1st with all other parameters shifting along.

Can I validate that the above assumption is correct and do you think there are any other similar refactoring changes that might trip me up?

BTW, the poll vote removal seems to work well!

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [October 8, 2021, 12:52pm UTC](https://meta.discourse.org/t/unvote-a-poll/50476/19 "2021-10-08T12:52:52Z")

</div>

> [@bletch](#):
>
> Can I validate that the above assumption is correct and do you think there are any other similar refactoring changes that might trip me up?

You are correct. I moved user to be the first parameter for most functions because that is the convention we usually follow.

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [October 18, 2021, 8:00am UTC](https://meta.discourse.org/t/unvote-a-poll/50476/20 "2021-10-18T08:00:11Z")

</div>

This topic was automatically closed after 9 days. New replies are no longer allowed.
