• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Disabling Option

R

ragtek

Guest
#1
Is there already any way, to make a option depending(disabled/enabled) from an other option?

For example:
inviteoptiondisa.PNG
Expiretime should only be enabled, if the "delete invites" checkbox is activated.


I know that the js is already coded
Code:
	/**
	 * Allows an input:checkbox or input:radio to disable subsidiary controls
	 * based on its own state
	 *
	 * @param {Object} $input
	 */
	XenForo.Disabler = function($input)
but can i use this without own templates for the options?
 

Shadab

Well-known member
#3
I think you'll have to create a "template" driven option. And in your template, create a nested xen:option tag. I believe the inner options would then depend on the outer option to be enabled or "checked" for it to work.
 
R

ragtek

Guest
#4
I think you'll have to create a "template" driven option. And in your template, create a nested xen:option tag. I believe the inner options would then depend on the outer option to be enabled or "checked" for it to work.
hm, didn't understand that:D
so i had to implement a own template with some jquery code to hide/show the elemets.

It's extremly ugly for example: $elem.parent().parent().hide() but it's working^^
 

Dr.Yontem

Formerly Tilkißey
#5
example from admin.php?options/list/twitter
this page is using "named template" format and its template's name is "option_template_tweet"
HTML:
<xen:checkboxunit label="" hint="{$preparedOption.hint}">
<xen:option name="{$fieldPrefix}[{$preparedOption.option_id}][enabled]" selected="{$preparedOption.option_value.enabled}">
<xen:label>{$preparedOption.title}</xen:label>
<xen:textbox name="{$fieldPrefix}[{$preparedOption.option_id}][via]" value="{$preparedOption.option_value.via}" placeholder="{xen:phrase via_twitter_account}" />
<xen:textbox name="{$fieldPrefix}[{$preparedOption.option_id}][related]" value="{$preparedOption.option_value.related}" placeholder="{xen:phrase related_twitter_account}" />
</xen:option>
<xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
<xen:html>
<input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
{xen:raw $editLink}
</xen:html>
</xen:checkboxunit>
 
R

ragtek

Guest
#6
example from admin.php?options/list/twitter
this page is using "named template" format and its template's name is "option_template_tweet"
HTML:
<xen:checkboxunit label="" hint="{$preparedOption.hint}">
<xen:option name="{$fieldPrefix}[{$preparedOption.option_id}][enabled]" selected="{$preparedOption.option_value.enabled}">
<xen:label>{$preparedOption.title}</xen:label>
<xen:textbox name="{$fieldPrefix}[{$preparedOption.option_id}][via]" value="{$preparedOption.option_value.via}" placeholder="{xen:phrase via_twitter_account}" />
<xen:textbox name="{$fieldPrefix}[{$preparedOption.option_id}][related]" value="{$preparedOption.option_value.related}" placeholder="{xen:phrase related_twitter_account}" />
</xen:option>
<xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
<xen:html>
<input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
{xen:raw $editLink}
</xen:html>
</xen:checkboxunit>
thx, but i've made it now an other way
IMHO the users shouldn't see anything, what's not usable^^
video: http://ragtek.org/videos/nuns.htm

(very handy that ajnos uploaded this some minutes ago:D for an other thread:D http://xenforo.com/community/threads/ragtek-new-user-mail.8701/page-2#post-195823)
 

xfrocks

Well-known member
#7
Ah ha, another related thread for http://xenforo.com/community/threads/js-challenge.15170/

You can do this

Code:
<xen:checkboxunit label="">
<xen:option name="name" value="value" inputclass="Disabler" id="checkbox_id_123" />
</xen:checkboxunit>

<div id="check_box_id_123_Disabler">
your other stuff goes here
</div>
You can choose to hide it or disable it only. Simply add one more class: "Hider"

PS: If this code doesn't work, you probably need to play around with the id. I'm not at my dev machine atm to test :p But it works, I swear!
 
R

ragtek

Guest
#8
With this i would need own templates for every option or?

ATM i've just created the "normal" options in the debugmode....

The problem is, that i've tried to add inputclass="Disabler" in the Format Parameters field, BUT it's not possible for checkboxes:(

Code:
<template title="option_list_option_onoff"><![CDATA[<xen:checkboxunit hint="{$preparedOption.hint}">
    <xen:label>{$_preparedOption.title}</xen:label>
    <xen:option name="{$fieldPrefix}[{$preparedOption.option_id}]" selected="{$preparedOption.option_value}">
        <xen:label>{$preparedOption.title}</xen:label>
        <xen:hint>{xen:raw $preparedOption.explain}</xen:hint>
    </xen:option>
    <xen:html>
        <input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
        {xen:raw $editLink}
    </xen:html>
</xen:checkboxunit>]]></template>
There's no place for the class^^
 

Beanjam

Active member
#9
How can I implement only the Hider?

I want to hide a select element, but retain its value in the database. The Disabler class deletes the value.

Alternatively, does anyone have a suggestion for how to select the first item in the select element automatically upon ticking the checkbox?

The problem I have is that users will tick the checkbox, enabling the select but then not choose an item from the list. I could set a default upon submission of the form, or display a required field error message, but prefer that it is dealt with before submission.