Skip to content

[3.0] Theme split (wave 4, part 12) — give the poll option editor one implementation - #9429

Open
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-poll-options
Open

[3.0] Theme split (wave 4, part 12) — give the poll option editor one implementation#9429
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-poll-options

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Part of the #7933 split (wave 4, part 12). Posting area, second of the two
slices, independent of #9428.

Post.template.php and Poll.template.php each generated their own near
identical copy of addPollOption() into the page, both seeded from a context
value the other one sets differently:

var pollOptionId = ', Utils::$context['last_choice_id'], ';

Post never sets last_choice_id when the poll is new. So the new poll
form at ?action=post;board=N;poll emits

var pollOptionId = ;

which is a syntax error, and the browser discards the whole first <script>
block with it:

Uncaught SyntaxError: Unexpected token ';'

Two things break as a result. Add Option does nothing, because
addPollOption was never defined. And the message icon preview stops
updating
, because icon_urls is declared in that same block and
script.js reads it to swap the image. smf_log_errors has been collecting
Undefined array key "last_choice_id" for the same page.

The add/edit poll form at ?action=editpoll is not affected — PollEdit does
set the value — which is presumably why this has gone unnoticed.

What changes

Both copies now come from Themes/default/scripts/post.js, loaded only where
there is a poll to edit. The option list carries the "Add Option" wording and
the numbered label as data attributes, so nothing is generated into the page any
more, and the button is written from script next to the list, which gets a
javascript: link out of the markup. pollOptions() moves here out of
script.js, which every page loads and only this form calls.

The new field copies its id and name from the last one with the trailing number
bumped, rather than building either from scratch. The two forms disagree about
what those look like — Poll::format() hands out ids that already begin with
options- and both templates prefix them again, giving
name="options[options-3]" — and following whatever the server just rendered
keeps the added option in the same shape as its neighbours without settling that
question here. It is worth its own look; on release-3.0 the edit poll form
adds options[5] next to options[options-4], so the two disagree today.

Testing

Both forms, on this branch: options add and number correctly and produce no
console errors, icon_urls is defined again, and the results-after-expiry radio
still follows the expiry field, including falling back to "after voting" when it
was selected and the expiry is cleared. A poll submitted from the posting form
with an option added by the button stores all three choices.

Issues References (Fixes|Related|Closes)

Related to #7933

… ones

Post.template.php and Poll.template.php each generated their own near identical
copy of addPollOption() into the page, both seeded from a context value the
other one sets differently:

	var pollOptionId = ', Utils::$context['last_choice_id'], ';

Post never sets last_choice_id at all when the poll is new, so the new poll form
at ?action=post;board=N;poll emitted

	var pollOptionId = ;

which is a syntax error, and the whole first script block went with it. Add
Option did nothing, because addPollOption was never defined, and neither was
icon_urls, which is declared in that same block and is what script.js reads to
swap the message icon preview. The error log has been collecting "Undefined
array key last_choice_id" for it.

Both copies now come from Themes/default/scripts/post.js, loaded only where
there is a poll to edit, with the option list carrying the "Add Option" wording
and the numbered label as data attributes. The button is written from script
next to the list, so the markup no longer has a javascript: link in it, and
pollOptions() moves here out of script.js, which every page loads and only this
form calls.

The new field copies its id and name from the last one with the trailing number
bumped, rather than building either from scratch. The two forms disagree about
what those look like - Poll::format() hands out ids that already start with
"options-" and both templates prefix them again - and following whatever the
server just rendered keeps the added option in the same shape as its neighbours
without settling that question here.

Verified on both forms: options add and number correctly, the results-after-
expiry radio still follows the expiry field, and a poll submitted with an option
added by the button stores all three choices.

Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@live627

live627 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Shouldn't it be poll.js since it only concerns polls?

Per review: post.js came from the theme branch, where the name looks ahead to a
general script for the posting form, but everything in it is about editing a
poll, and one of the two places that loads it is the add/edit poll form rather
than the posting form at all. The handle goes from smf_post to smf_poll with it.

Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@albertlast

Copy link
Copy Markdown
Collaborator Author

Agreed, and it was worse than just the name — PollEdit loads it too, so one of the two callers is not the posting form at all. Renamed to poll.js, handle smf_postsmf_poll, and the file comment now says what it is rather than "the bits of the posting form that...".

post.js came straight from the theme branch, where the name looks ahead to a general posting script. Nothing there fills it out either — its copy holds the same two poll functions — so there is nothing lost by naming it for what it does now.

Re-checked both forms after the rename: options add and number correctly on the new poll form and the add/edit poll form, the results-after-expiry radio still follows the expiry field, icon_urls is still defined, and no console errors.

@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants