[3.0] Theme split (wave 4, part 12) — give the poll option editor one implementation - #9429
[3.0] Theme split (wave 4, part 12) — give the poll option editor one implementation#9429albertlast wants to merge 2 commits into
Conversation
… 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>
|
Shouldn't it be |
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>
|
Agreed, and it was worse than just the name —
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, |
Description
Part of the #7933 split (wave 4, part 12). Posting area, second of the two
slices, independent of #9428.
Post.template.phpandPoll.template.phpeach generated their own nearidentical copy of
addPollOption()into the page, both seeded from a contextvalue the other one sets differently:
var pollOptionId = ', Utils::$context['last_choice_id'], ';Postnever setslast_choice_idwhen the poll is new. So the new pollform at
?action=post;board=N;pollemitswhich is a syntax error, and the browser discards the whole first
<script>block with it:
Two things break as a result. Add Option does nothing, because
addPollOptionwas never defined. And the message icon preview stopsupdating, because
icon_urlsis declared in that same block andscript.jsreads it to swap the image.smf_log_errorshas been collectingUndefined array key "last_choice_id"for the same page.The add/edit poll form at
?action=editpollis not affected —PollEditdoesset the value — which is presumably why this has gone unnoticed.
What changes
Both copies now come from
Themes/default/scripts/post.js, loaded only wherethere 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 ofscript.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 withoptions-and both templates prefix them again, givingname="options[options-3]"— and following whatever the server just renderedkeeps the added option in the same shape as its neighbours without settling that
question here. It is worth its own look; on
release-3.0the edit poll formadds
options[5]next tooptions[options-4], so the two disagree today.Testing
Both forms, on this branch: options add and number correctly and produce no
console errors,
icon_urlsis defined again, and the results-after-expiry radiostill 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