<select> inside a <xen:option>

llk

Member
I'm trying to create a template modification that adds a new option to a radio unit in an admin template. This existing radio unit looks like so:

Code:
<xen:radiounit label="..." name="...">
  <xen:option value="...">...</xen:option>
  ...
</xen:radiounit>

I want my new option to contain a drop-down menu whose options are pulled from an array set by the view controller, but I can't for the life of me figure out the syntax for it. I've tried <xen:selectunit>, <xen:select>, and plain-old <select>, combined with <xen:options> or just <xen:option> inside an <xen:foreach>, and nothing works. How do I do this?
 
Any ideas? I can put a statically-populated <select> inside a <xen:option> and it works fine. I just can't figure out how to populate that drop-down from an array in a template var.
 
Sorry if I posted this in the wrong forum initially.

Suggestions? Any help would be appreciated, including alternatives or work-arounds.
 
I overlooked this thread, sorry.

I think what you're looking for is something like this:
Code:
<xen:radiounit label="..." name="...">
  <xen:option value="...">...</xen:option>
  <xen:option value="...">
      <xen:disabled>
        <xen:select name="...">...</xen:select>
      </xen:disabled>
  </xen:option>
</xen:radiounit>
 
I think what you're looking for is something like this:
Code:
<xen:radiounit label="..." name="...">
  <xen:option value="...">...</xen:option>
  <xen:option value="...">
      <xen:disabled>
        <xen:select name="...">...</xen:select>
      </xen:disabled>
  </xen:option>
</xen:radiounit>
I can't find any documentation on xen:disabled; what does it do? In any case, it doesn't seem to change anything. BTW, what is the difference between plain <select> and <xen:select>?

To be more concrete, here's a simplified version of the admin template mod I'm working on. The template name is user_moderated, and I'm searching for <xen:option value="reject"> and prepending this ($userGroups is just an array of user groups in [$id => $name] format):

Code:
<xen:option value="move">{xen:phrase move_to_group}
	<xen:disabled>
		<xen:select name="move_to_group">
			<xen:foreach loop="$userGroups" key="$id" value="$name">
				<xen:option value="{$id}">{$name}"</xen:option>
			</xen:foreach>
		</xen:select>
	</xen:disabled>
</xen:option>

The entire outer option fails to appear when I use this code, or any variation of it I've tried except for a plain <select> with a static set of sub-options (no xen:select, xen:disabled, or xen:foreach). It seems that when XF doesn't like the contents a <xen:option> it discards the whole thing, but is there anywhere I can see an error message describing what's wrong? There's nothing in our server error log.
 
You're nearly there.

I suspect the template modification isn't applying, you can see if it applies or not from the TM list:

upload_2017-7-20_0-37-42.webp

The red 1 there indicates an error.

Specifically I think the problem is your option tag:

Code:
<xen:option value="move">{xen:phrase move_to_group}

The label must be in either a "label" attribute, in an "<xf:label>" tag or the only "child" within the tag. In your case, you've got your label amongst all of the other stuff within the tag so it's not valid.

Essentially, just change it to this:

Code:
<xen:option value="move" label="{xen:phrase move_to_group}">

And as far as I can tell that should solve it.
 
The red 1 there indicates an error.
Ah, that is a useful tip. It might be better for XF to hide that last number when it's a zero, since otherwise it's very easy to miss a single '1'.
The label must be in either a "label" attribute, in an "<xf:label>" tag or the only "child" within the tag.
That was it. Thanks!

For future reference, are there more comprehensive docs for XF template syntax than https://xenforo.com/community/resources/template-syntax-xenforo-tags.2122/ anywhere? I hate having to bug you guys for simple questions like this, but it can be hard to figure some things out even by reading the source.
 
Back
Top Bottom