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…

6 Likes