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

[Question] How to implement conditional options?

SchmitzIT

Well-known member
#1
I actually have two questions.

1) In the Options menu, I'd like to try and see if the following is possible. I provide a checkbox, and set it do disabled by default. Below it, I would like to add a set of options that would only be relevant if the checkbox above is checked. Ideally, I would hide them altogether, or disable them to visually show they are irrelevant until the ceckbox is turned on.

Is that possible?

2) Again, in the options, I would like to do the following. I fire off a query towards the database, and it comes back with a few results. I have seen and used the code by Lawrence as a basis, and use Lawrence's code pretty much unedited for a different part of the add-on.

However, rather than displaying a list of checkboxes, I'd like to do something along the following lines in the current part of the add-on that I'm working on. My query has one column detailing CSS code, and another one providing a name.

I want to pass the array returned by my query to a template, and display the CSS as a label, and then have a textbox with a value of the second column, that can be edited by the user. I'll need to store whatever values the user enters for later use.

How would I go about achieving that?

Thanks in advance :)
 
F

Floris

Guest
#2
If you make a group in the admin.php > options
And in this group you add a unique id called EP_MyOption

Then in a template you can use: <xen:if is="{$xenOptions.EP_MyOption} == 1">assuming value is a valid one</xen:if>

In PHP it's just if ($xenOptions.EP_MyOption == '1') { .. }

At least, that's what I hope you were looking for. Regarding the checkbox options comment.
 

SchmitzIT

Well-known member
#3
Thanks for your reply, Floris.

I'm actually aiming at the check to be done within the same admin options page.

I.e. I have an option group for my add-on. In that, I have a checkbox stating: "Enable add-on?". There are more options below it, but they will not show until the checkbox is enabled.

Does that make sense?
 
F

Floris

Guest
#4
Ah yes, that makes sense. You mean how reCaptcha has done it for mail? Unless checked, the callback won't enable it.

I wonder if that's done via javascript btw. Haven't played with that part yet. But I believe it uses a controller to get the other options below it. I am probably so wrong :p
 

SchmitzIT

Well-known member
#5
I just am not sure it can currently be done. I wouldn't know where to put that in the definition of the option screen, other than perhaps wrapping my entire option screen in a template, which (i think), would make me lose part of the control over the rest of the abilities provided by the option screen.
 
F

Floris

Guest
#6
I see captcha using a callback, I wonder if the callback checks against the status live, or perhaps a quick js check, options are only live when pressed on submit, so you can re-use the existing js. Maybe Kier or Mike or David can respond.