• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Hide Poll options when creating a thread

Marcus

Well-known member
From this suggestion: http://xenforo.com/community/threads/user-interface-hide-poll-options-when-creating-a-thread.1362/ Vote for it if you want to implement it to the core. This template modification will add a phrased "Add poll" button between "Add file" and "Preview"

1.webp

which turns on the then deactivated poll options.

2.webp

Like this post if you install this modification.

New installation advice from Morgain for template thread_create:
I got it to work nicely but it always makes me nervous to replace a large amount of code all at once.
So I went through it and made notes on exactly where to insert 3 bits of new code.

FIRST
Rich (BB code):
<input type="submit" value="{xen:phrase create_thread}" accesskey="s" class="button primary" />
<xen:include template="attachment_upload_button" />
<!– ADD –>  <input type="button" value="{xen:phrase post_poll}" class="button DisableOnSubmit JsOnly" id="button_post_poll") />
<!– END ADD –>

SECOND
Rich (BB code):
<xen:hook name="thread_create_fields_extra" params="{xen:array 'forum={$forum}'}" />
<!– ADD –>  <div id="post_poll" style="display:none">
<!– END ADD –>]

THIRD
Rich (BB code):
    <input type="submit" value="{xen:phrase create_thread}" class="button primary" />
    <input type="button" value="{xen:phrase preview}..." class="button PreviewButton JsOnly" />
        </dd>
    </dl>
 
<!– ADD –>  </div>
<script>$('#button_post_poll').click(function() {
  $('#post_poll').slideToggle();
});</script>
<!– END ADD –>
 
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
<xen:comment><xen:include template="editor" /></xen:comment>


Old installation advice: In template thread_create replace everything after <!-- slot: after_editor --> with

Code:
<!-- slot: after_editor -->
 
<dl class="ctrlUnit submitUnit">
<dt></dt>
<dd>
<input type="submit" value="{xen:phrase create_thread}" accesskey="s" class="button primary" />
<xen:include template="attachment_upload_button" />
 
<input type="button" value="{xen:phrase post_poll}" class="button DisableOnSubmit JsOnly" id="button_post_poll") />
 
<input type="button" value="{xen:phrase preview}..." class="button PreviewButton JsOnly" />
</dd>
</dl>
 
<xen:if is="{$attachmentParams}">
<dl class="ctrlUnit AttachedFilesUnit">
<dt><label for="ctrl_uploader">{xen:phrase attached_files}:</label></dt>
<dd><xen:include template="attachment_editor" /></dd>
</dl>
 
<!-- slot: after_attachment -->
</xen:if>
 
<xen:if is="{$visitor.user_id}">
<fieldset>
<dl class="ctrlUnit">
<dt>{xen:phrase options}:</dt>
<dd><ul>
<li><xen:include template="helper_thread_watch_input" /></li>
</ul></dd>
</dl>
 
<xen:include template="thread_fields_status" />
</fieldset>
 
<!-- slot: after_options -->
</xen:if>
 
<xen:hook name="thread_create_fields_extra" params="{xen:array 'forum={$forum}'}" />
 
<div id="post_poll" style="display:none">
 
<h3 class="textHeading">{xen:phrase post_poll}</h3>
<dl class="ctrlUnit">
<dt><label for="ctrl_poll_question">{xen:phrase question}:</label></dt>
<dd><input type="text" name="poll[question]" class="textCtrl" id="ctrl_poll_question" maxlength="100" /></dd>
</dl>
<dl class="ctrlUnit">
<dt>{xen:phrase possible_responses}:</dt>
<dd>
<ul class="PollResponseContainer">
<li><input type="text" name="poll[responses][]" class="textCtrl" placeholder="{xen:phrase poll_choice}..." maxlength="100" /></li>
<li><input type="text" name="poll[responses][]" class="textCtrl" placeholder="{xen:phrase poll_choice}..." maxlength="100" /></li>
</ul>
<input type="button" value="{xen:phrase add_additional_response}" class="button smallButton FieldAdder" data-source="ul.PollResponseContainer li" data-maxfields="{$xenOptions.pollMaximumResponses}" />
</dd>
</dl>
<!-- slot: after_poll_responses -->
<dl class="ctrlUnit">
<dt></dt>
<dd>
<ul>
<li><label for="ctrl_poll_multiple"><input type="checkbox" name="poll[multiple]" value="1" id="ctrl_poll_multiple" /> {xen:phrase allow_selection_of_multiple_responses}</label></li>
<li><label for="ctrl_poll_public_votes"><input type="checkbox" name="poll[public_votes]" value="1" id="ctrl_poll_public_votes" /> {xen:phrase display_votes_publicly}</label></li>
<li><label for="ctrl_poll_close"><input type="checkbox" name="poll[close]" value="1" class="Disabler" id="ctrl_poll_close" /> {xen:phrase close_this_poll_after}:</label>
<ul id="ctrl_poll_close_Disabler">
<li>
<input type="text" size="5" name="poll[close_length]" value="7" class="textCtrl autoSize" />
<select name="poll[close_units]" class="textCtrl autoSize">
<option value="hours">{xen:phrase hours}</option>
<option value="days" selected="selected">{xen:phrase days}</option>
<option value="weeks">{xen:phrase weeks}</option>
<option value="months">{xen:phrase months}</option>
</select>
</li>
</ul>
</li>
</ul>
</dd>
</dl>
 
</xen:hook>
 
<dl class="ctrlUnit submitUnit">
<dt></dt>
<dd>
<input type="submit" value="{xen:phrase create_thread}" class="button primary" />
<input type="button" value="{xen:phrase preview}..." class="button PreviewButton JsOnly" />
</dd>
</dl>
</div>
<script>$('#button_post_poll').click(function() {
  $('#post_poll').slideToggle();
});</script>
 
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 
<xen:comment><xen:include template="editor" /></xen:comment>
 
Suggestions if someone wants to improve this modification:
- auto-scroll to the poll section when activate it
- auto-scroll back to window top when you deactivate the poll section
 
amazing idea to shorten the page and keeping it simple. Is it possible to make it appear before the thread's subscribe option (y)
 
I know it's rare, but what happens in the event of a user browsing with no javascript enabled?
You can change the script to hide the poll area with javascript. If the user does not have javascript, the poll area is not hidden.
 
Maybe I am missing something but I don't seem to have the text <!-- slot: after_editor --> in my thread_create template.

When I try to replace the content after <dl class="ctrlUnit submitUnit"> it gives me a syntax error.

The template is unmodified. Here are the contents, could it be an addon I have installed changed it? The template is still blue in the templates list suggesting that it hasn't been touched though. Any help would be appreciated, thanks in advance.

EDIT: I am using XF 1.0.4 if that helps.

Code:
<xen:title>{xen:phrase create_thread}</xen:title>
 
<xen:if is="{$forum.description} AND @threadListDescriptions">
    <xen:description class="baseHtml">{xen:raw $forum.description}</xen:description>
</xen:if>
 
<xen:navigation>
    <xen:breadcrumb source="$nodeBreadCrumbs" />
</xen:navigation>
 
<xen:container var="$head.robots">
    <meta name="robots" content="noindex" /></xen:container>
 
<form action="{xen:link 'forums/add-thread', $forum}" method="post"
    class="xenForm Preview AutoValidator"
    data-previewUrl="{xen:link 'forums/create-thread/preview', $forum}"
    data-redirect="on"
>
 
    <xen:if is="{$visitor.user_id} == 0">
        <dl class="ctrlUnit">
            <dt><label for="ctrl_guestUsername">{xen:phrase name}:</label></dt>
            <dd><input type="text" name="_guestUsername" value="{$visitor.username}" class="textCtrl" /></dd>
        </dl>
    </xen:if>
 
    <xen:include template="helper_captcha_unit" />
 
    <fieldset>
        <dl class="ctrlUnit">
            <dt><label for="ctrl_title">{xen:phrase title}:</label></dt>
            <dd><input type="text" name="title" class="textCtrl" data-liveTitleTemplate="{xen:phrase create_thread}: <em>%s</em>" id="ctrl_title" maxlength="100" autofocus="true" /></dd>
        </dl>
 
        <xen:hook name="thread_create_fields_main" params="{xen:array 'forum={$forum}'}" />
 
        <dl class="ctrlUnit fullWidth">
            <dt></dt>
            <dd>{xen:raw $editorTemplate}</dd>
        </dl>
    </fieldset>
 
    <dl class="ctrlUnit submitUnit">
        <dt></dt>
        <dd>
            <input type="submit" value="{xen:phrase create_thread}" accesskey="s" class="button primary" />
            <xen:include template="attachment_upload_button" />
            <input type="button" value="{xen:phrase preview}..." class="button PreviewButton JsOnly" />
        </dd>
    </dl>
 
    <xen:if is="{$attachmentParams}">
        <dl class="ctrlUnit AttachedFilesUnit">
            <dt><label for="ctrl_uploader">{xen:phrase attached_files}:</label></dt>
            <dd><xen:include template="attachment_editor" /></dd>
        </dl>
    </xen:if>
 
    <xen:if is="{$visitor.user_id}">
        <fieldset>
            <dl class="ctrlUnit">
                <dt>{xen:phrase options}:</dt>
                <dd><ul>
                    <li><xen:include template="helper_thread_watch_input" /></li>
                </ul></dd>
            </dl>
 
            <xen:include template="thread_fields_status" />
        </fieldset>
    </xen:if>
 
    <xen:hook name="thread_create_fields_extra" params="{xen:array 'forum={$forum}'}" />
 
    <h3 class="textHeading">{xen:phrase post_poll}</h3>
    <dl class="ctrlUnit">
        <dt><label for="ctrl_poll_question">{xen:phrase question}:</label></dt>
        <dd><input type="text" name="poll[question]" class="textCtrl" id="ctrl_poll_question" maxlength="100" /></dd>
    </dl>
    <dl class="ctrlUnit">
        <dt>{xen:phrase possible_responses}:</dt>
        <dd>
            <ul class="PollResponseContainer">
                <li><input type="text" name="poll[responses][]" class="textCtrl" placeholder="{xen:phrase poll_choice}..." maxlength="100" /></li>
                <li><input type="text" name="poll[responses][]" class="textCtrl" placeholder="{xen:phrase poll_choice}..." maxlength="100" /></li>
            </ul>
            <input type="button" value="{xen:phrase add_additional_response}" class="button smallButton FieldAdder" data-source="ul.PollResponseContainer li" data-maxfields="{$xenOptions.pollMaximumResponses}" />
        </dd>
    </dl>
    <dl class="ctrlUnit">
        <dt></dt>
        <dd>
            <ul>
                <li><label for="ctrl_poll_multiple"><input type="checkbox" name="poll[multiple]" value="1" id="ctrl_poll_multiple" /> {xen:phrase allow_selection_of_multiple_responses}</label></li>
                <li><label for="ctrl_poll_public_votes"><input type="checkbox" name="poll[public_votes]" value="1" id="ctrl_poll_public_votes" /> {xen:phrase display_votes_publicly}</label></li>
                <li><label for="ctrl_poll_close"><input type="checkbox" name="poll[close]" value="1" class="Disabler" id="ctrl_poll_close" /> {xen:phrase close_this_poll_after}:</label>
                    <ul id="ctrl_poll_close_Disabler">
                        <li>
                            <input type="text" size="5" name="poll[close_length]" value="7" class="textCtrl autoSize" />
                            <select name="poll[close_units]" class="textCtrl autoSize">
                                <option value="hours">{xen:phrase hours}</option>
                                <option value="days" selected="selected">{xen:phrase days}</option>
                                <option value="weeks">{xen:phrase weeks}</option>
                                <option value="months">{xen:phrase months}</option>
                            </select>
                        </li>
                    </ul>
                </li>
            </ul>
        </dd>
    </dl>
 
    <dl class="ctrlUnit submitUnit">
        <dt></dt>
        <dd>
            <input type="submit" value="{xen:phrase create_thread}" class="button primary" />
            <input type="button" value="{xen:phrase preview}..." class="button PreviewButton JsOnly" />
        </dd>
    </dl>
 
    <input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 
<xen:comment><xen:include template="editor" /></xen:comment>
 
This modification works like this:

1. hide the poll with this statement:

<div id="post_poll" style="display:none">here is the code of the poll</div>


2. add the "Post Poll" button with this statement:

<input type="button" value="{xen:phrase post_poll}" class="button DisableOnSubmit JsOnly" id="button_post_poll") />

3. Activate the button so it hides and shows the hidden poll area with this statement:

<script>$('#button_post_poll').click(function() {$('#post_poll').slideToggle();});</script>
 
OK I too don't have the line you gave as a landmark.
<!-- slot: after_editor -->
I think this is your own comment to start the code insertion.

I also need to know exactly what to insert where because I have a sidebar added to the page at the bottom.
I'm assuming your replacement goes down to
Code:
<xen:comment><xen:include template="editor" /></xen:comment>
which is the last line on the standard page of code.

Where does the insertion / replacement begin please?

I tried putting in the 3 lines you gave above, placing after the hook line:
Code:
<xen:hook name="thread_create_fields_extra" params="{xen:array 'forum={$forum}'}" />
 
<div id="post_poll" style="display:none">here is the code of the poll</div>
<input type="button" value="{xen:phrase post_poll}" class="button DisableOnSubmit JsOnly" id="button_post_poll") />
<script>$('#button_post_poll').click(function() {$('#post_poll').slideToggle();});</script>

This gives an error - XF refuses to save it.

Lovely mod if I can get it to work. I actually suggested it and was directed here!
 
OK I found in the standard XF code in

Code:
    <dl class="ctrlUnit submitUnit">

That matches the first line of your code.
So I replaced all the existing code with yours up to

Code:
<xen:comment><xen:include template="editor" /></xen:comment>
which is the last line of the original code.

I still get an error with XF refusing to save it. Error message
The following templates contained errors and were not saved: thread_create: 1) Line 128: Template syntax error.

Maybe I have the wrong start point for the replacement.
 
OK I found in the standard XF code in

Code:
    <dl class="ctrlUnit submitUnit">

That matches the first line of your code.
So I replaced all the existing code with yours up to

Code:
<xen:comment><xen:include template="editor" /></xen:comment>
which is the last line of the original code.

I still get an error with XF refusing to save it. Error message
The following templates contained errors and were not saved: thread_create: 1) Line 128: Template syntax error.

Maybe I have the wrong start point for the replacement.
I was getting the same error too. I ended up just giving up. I haven't tried it will 1.1 yet, might give it a shot tonight.
 
Top Bottom