Overriding poll default so "public=true"

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

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.

2 Likes

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:

<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:

<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.

2 Likes

Itā€™s great you figured it out. :+1:

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

    this.setProperties({
        'publicPoll': true,
        'showAdvanced': true
    });
2 Likes

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

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

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

2 Likes

Iā€™ve tested it and it works! :partying_face:

Thatā€™s fantastic. :slight_smile: Thank you very much. :pray:

1 Like

And here it is as a Theme Component:

4 Likes

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 ?

1 Like

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 dev topic :+1:

2 Likes

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

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

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?

1 Like

Good news. :slight_smile: I think we may have something for thisā€¦

4 Likes