# Overriding poll default so "public=true"

**URL:** https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722
**Category:** Development
**Tags:** polls
**Created:** [May 25, 2023, 7:28am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722 "2023-05-25T07:28:55Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![elRicharde](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@elRicharde](https://meta.discourse.org/u/elRicharde)
#### Post date: [May 25, 2023, 7:28am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/1 "2023-05-25T07:28:55Z")

</div>

> [@Making polls ‘Show who voted’ by default](https://meta.discourse.org/t/making-polls-show-who-voted-by-default/220022/1):
>
> they always seem to _forget_ to select the check-mark **Show who voted**. Is there any way to set this as a default?

i was wondering how many sites struggling with this as well. I also would love to have it Public by Standard.

> [@Making polls ‘Show who voted’ by default](https://meta.discourse.org/t/making-polls-show-who-voted-by-default/220022/5):
>
> I think the change in poll UI a while back made them a little less intuitive when it comes to the ‘single choice’ versus ‘multiple choice’, as people seem to think that ‘single choice’ means single option. So they pick ‘multiple’, and adjust the min/max to make it a single choice poll. 🙂

I also think the UI could be better.

- You can make single Vote Polls from MultiVote Polls, so there is no need to have single in my opinion
- I would always show the extended UI
- I would love the option Public=True as Standard or if easier to implement Anonymous=False
- I would move the Checkbox for Public on Top or make UI for Public and for anonymous Polls separately, it gets overseen too easy

I´m not familiar with changing theme components, if there is an easy workaround for now that someone made it would be awesome to share with instructions how to implement and what to check when updating Discourse.

---

<div class="post-metadata">

### Author: ![elRicharde](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@elRicharde](https://meta.discourse.org/u/elRicharde)
#### Post date: [May 26, 2023, 11:38am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/2 "2023-05-26T11:38:08Z")

</div>

> [@Making polls ‘Show who voted’ by default](https://meta.discourse.org/t/making-polls-show-who-voted-by-default/220022/3):
>
> Would it be possible to get a hint as to what I’m doing wrong?

I´m a newby but interested in solving the problem so I asked chat-gpt:

Here is the answer:

> The script you found is a good start. It’s modifying the `poll-ui-builder` controller to set the `publicPoll` property to `true` when the controller’s `onShow()` function is called. This is indeed intended to be added as a Theme Component.
> 
> However, the code might not be working due to the order of execution. The original `onShow()` method sets `publicPoll` to `false` and then the modification sets `publicPoll` to `true` afterwards.
> 
> A correct way would be to call the parent’s `onShow` method first, and then set `publicPoll` to `true`:

```js
<script type="text/discourse-plugin" version="0.8">
api.modifyClass("controller:poll-ui-builder", {
  onShow() {
    this._super(...arguments);
    this.set('publicPoll', true);
  }
});
</script>

```

> You can add this script to your theme by following these steps:
> 
> 1. Go to the Discourse Admin dashboard.
> 2. Under the “Customize” section, click on “Themes”.
> 3. Select the theme that you want to modify.
> 4. In the theme editing screen, click on “Edit CSS/HTML”.
> 5. In the left sidebar, click on “\</\> Common”.
> 6. Paste the above script into the “\</\> Common” section.
> 7. Click on the “Save” button.
> 
> This will apply the change to your theme. Please remember that theme changes are only applied to users who are using that particular theme. If you have multiple themes, you’ll need to add this modification to each one.
> 
> Also, remember to clear your browser cache or do a hard reload to ensure that the changes are loaded correctly.

I will try to follow these steps with the admin of our Forum, but this takes a while, if someone else here want to try this in first please and give feedback I would be very happy.

Another thing i would love to change is the behaviour of the ui, i want to skip the simple screen, so i asked chat-gpt again:

> In your current code, the extended view is controlled by the `showAdvanced` property. If this is set to `true`, the advanced view will be shown.
> 
> To always show the advanced view, you can modify the `onShow()` method in the `poll-ui-builder` controller to set `showAdvanced` to `true`. You can add this modification to the theme component you created earlier. Here’s the updated script:

```js
<script type="text/discourse-plugin" version="0.8">
api.modifyClass("controller:poll-ui-builder", {
  onShow() {
    this._super(...arguments);
    this.set('publicPoll', true);
    this.set('showAdvanced', true);
  }
});
</script>

```

> Remember to follow the steps I previously outlined to add this script to your theme. Once the script is saved, the advanced view should always be shown when the poll UI is loaded.
> 
> Again, remember to clear your browser cache or do a hard reload to ensure that the changes are loaded correctly.

I would love to try and test by myself somehow, but as mentioned before i´m just a moderator, not the admin of our site, so this will take some days or weeks.

---

<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: [May 26, 2023, 12:07pm UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/3 "2023-05-26T12:07:24Z")

</div>

> [@elRicharde](#):
>
> ```js
> this.set('publicPoll', true);
> this.set('showAdvanced', true);
> 
> ```

It’s great you figured it out. 👍

Just as a side note, when you want to modify multiple properties, you can use this syntax:

```js
    this.setProperties({
        'publicPoll': true,
        'showAdvanced': true
    });

```

---

<div class="post-metadata">

### Author: ![elRicharde](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@elRicharde](https://meta.discourse.org/u/elRicharde)
#### Post date: [May 26, 2023, 12:10pm UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/4 "2023-05-26T12:10:10Z")

</div>

> [@Canapin](#):
>
> It’s great you figured it out.

not really me, I just feed Chat-GPT with the Code given from this link:

> [@Making polls ‘Show who voted’ by default](https://meta.discourse.org/t/making-polls-show-who-voted-by-default/220022/2):
>
> Here’s the property that controls if it is checked or unchecked: [discourse/poll-ui-builder.js at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js#L51)

and then give him the first try from @JammyDodger and asked if he could solve my two requirements 😃

would be great if it works and another cool thing about discourse i learned.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [May 26, 2023, 12:16pm UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/5 "2023-05-26T12:16:10Z")

</div>

> [@elRicharde](#):
>
> would be great if it works and another cool thing about discourse i learned.

I’ve tested it and it works! 🥳

That’s fantastic. 🙂 Thank you very much. 🙏

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [June 15, 2023, 3:39am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/6 "2023-06-15T03:39:57Z")

</div>

And here it is as a Theme Component:

> [@Poll Defaults](https://meta.discourse.org/t/poll-defaults/268399):
>
> information_sourceSummary Sets the defaults for polls within Discoursehammer_and_wrenchRepository [GitHub - nathan-nz/discourse-poll-defaults: Sets the defaults for polls within Discourse](http://github.com/nathan-nz/discourse-poll-defaults)questionInstall Guide [How to install a theme or theme component](https://meta.discourse.org/t/how-do-i-install-a-theme-or-theme-component/63682)open_bookNew to Discourse Themes? [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) Install this theme component This simple theme component allows some control over the default poll behaviour. It was inspired by this T…

---

<div class="post-metadata">

### Author: ![elRicharde](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@elRicharde](https://meta.discourse.org/u/elRicharde)
#### Post date: [September 21, 2023, 6:38am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/7 "2023-09-21T06:38:33Z")

</div>

doesn´t work anymore for our instance.  
couldn´t check if the code snippet is still in, as i do not have the permissions for that.

Does it still work in your forums @JammyDodger and @nathank ?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 21, 2023, 7:35pm UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/8 "2023-09-21T19:35:56Z")

</div>

I don’t think it’s working on my test site now either. It may need updating to account for some recent changes?

I’ll split this off into a #Development topic 👍

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [November 6, 2023, 9:25pm UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/9 "2023-11-06T21:25:14Z")

</div>

I’ve worked out that the modal this was calling has been refactored in accordance with this:

> [@Converting modals from legacy controllers to new DModal component API](https://meta.discourse.org/t/converting-modals-from-legacy-controllers-to-new-dmodal-component-api/268057):
>
> information_source If you’re implementing a new Modal, check out the main docs [here](https://meta.discourse.org/t/268304). This topic describes how to migrate an existing controller-based Modal to the new Component-based API. In the past, Discourse used an Ember-Controller-based API for rendering modals. To invoke the modal, you would pass a string with the name of the controller to showModal(). Under the covers, this made use of Ember’s Route#renderTemplate API, which is deprecated in Ember 3.x and will be removed in Ember 4.x…

However, I can’t work out how to interact with that via the API. The new modal file is here:

[https://github.com/discourse/discourse/blob/main/plugins/poll/assets/javascripts/discourse/components/modal/poll-ui-builder.js](https://github.com/discourse/discourse/blob/main/plugins/poll/assets/javascripts/discourse/components/modal/poll-ui-builder.js)

I can’t work out how to call this now, as how to do this isn’t covered in the documentation as far as I can tell. Can anyone help?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 13, 2023, 7:46am UTC](https://meta.discourse.org/t/overriding-poll-default-so-public-true/279722/10 "2023-11-13T07:46:32Z")

</div>

Good news. 🙂 I think we may have something for this…

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