Page 1 of 1

[SOLVED] LISE - checkbox group - selected checkbox text

Posted: Wed Apr 03, 2019 3:51 pm
by manuel
Hi all,

Maybe I'm overlooking something but how can I get the text of a selected checkbox option in a checkbox group to show up in the template?

I'm using multiple checkbox groups where some checkboxes have the same text so I need to enter unique values to be able to differentiate.

ex:
Checkbox group 1
Search=SearchGroup1
...

Checbox group 2
Search=SearchGroup2
...

Code below would return the values SearchGroup1 & SearchGroup2

Code: Select all

{foreach from=$fielddef->values item='value'}
  {$value}
{/foreach}
But I can't find how to return the text "Search"

Some extracts from the module with debugging turned on:
- The checkbox options list does still show both text and value:

Code: Select all

[options] => Support=OthSup
Families=OthFam
- The selected checkbox shows only the value of the checkbox option:

Code: Select all

[values] => Array
  (
    [0] => OthSup
  )
I'm thinking about a messy workaround but hope I'm just missing some insight :)

ps: I'm working in the "Search Template" to generate the filter buttons.

Greetings,
Manuel

Re: LISE - checkbox group - selected checkbox text

Posted: Wed Apr 03, 2019 6:21 pm
by manuel
messy workaround:
I changed the checkbox values to no longer contain separate values for text.

ex:
Checkbox group name:
"Something something"

Checkbox group options:
"Something something::The text I want to have appear in the filter button"
"Something something::Some other text I want to have appear"

Now, in the template, I can get the text I want by adding a replace...

Code: Select all

{foreach from=$fielddef->values item='value'}
  {$value|replace:"{$fielddef->name}::":''}
{/foreach}
If there where no repetitions of the same text in the checkbox group options of the various checkbox groups, this issue wouldn't exist as everything would be unique anyway...

The downside for this workaround besides the extra replace is that content editors will see "Something something::The text I want to have appear in the filter button" besides the checkbox in the backend but it's acceptable for me if it does the trick to get the correct text on the filter buttons in the frontend...

Greetings,
Manuel

Re: LISE - checkbox group - selected checkbox text

Posted: Wed Apr 03, 2019 6:29 pm
by velden
Hi Manuel,

Find one approach I could come up with below.

GetOptions is an undocumented method so use at your own discretion.

Code: Select all

{$option_values = $fielddef->GetOptions()}
			<select name="{$actionid}search_{$fielddef->alias}" id="filter_{$fielddef->alias}">
				<option value=''>{$mod->ModLang('all')}</option>
				{foreach from=$fielddef->values item=value}
				<option value="{$value}">{$option_values[$value]}</option>
				{/foreach}
			</select>

Re: LISE - checkbox group - selected checkbox text

Posted: Wed Apr 03, 2019 6:54 pm
by manuel
Oooh, nice one Velden, thanks! :)
I'll just add the URL to this thread in the code should it break with future upgrades but I'll switch to the solution you suggest! (tested and works) :)

Greetings,
Manuel

Re: [SOLVED] LISE - checkbox group - selected checkbox text

Posted: Wed Apr 03, 2019 8:13 pm
by calguy1000
,<cough>
see the smarty plugin {html_options}
</cough>

Re: [SOLVED] LISE - checkbox group - selected checkbox text

Posted: Thu Apr 04, 2019 7:48 am
by velden
calguy1000 wrote:,<cough>
see the smarty plugin {html_options}
</cough>
It should be noted that

a. LISE originally doesn't provide the input for {html_options}
b. The GetOptions() will return ALL options where '$fielddef->values' will be limited to actually relevant values*

*It will not show values which aren't used in any item. Also - though didn't check - that it may be limited by using other filters like categories etc.