LISE: using field definitions in the filter module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

LISE: using field definitions in the filter module

Post by blackrain »

I am trying to use a custom field definition as a conditional in the filter module of an LISE Instance.

The following snippet of code is a dropdown that allows the user to filter the results based on what the value of the dropdown (it uses javascript to apply the filter).

The dropdown is generated by the 'LISE Instance Item' custom field definition

The following code is how I think it should work, but alas it does not.

Code: Select all

{foreach from=$fielddefs item=fielddef}
	{if $fielddef.type != 'Categories'}
	    <select class="wide select-filter" name="{$actionid}search_{$fielddef->alias}" id="filter_{$fielddef->alias}">
	        <option value='all-{$fielddef->name|escape|lower|replace:' ':'-'}'>{$fielddef->name}</option>
	        {foreach from=$fielddef->values item=value}
                {if $value.child-service ne '1'}
	        <option value="{$value|escape|lower|replace:'&':'and'|replace:' ':'-'}">{$value}</option>
                {/if}
	        {/foreach}
	    </select>
	{/if}
{/foreach}
I am trying to return only LISE Instance Items that have 'child-service' as 'false'

Any ideas are welcome.

cheers

Mark
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: LISE: using field definitions in the filter module

Post by velden »

You should check the 'the contents' of the $value variable.

For the sake of efficiency it would make sense the module developer doesn't create a whole LISE item object just to build a filter. So my guess is it won't be easy to fix it in an efficient way.

Code: Select all

{foreach from=$fielddef->values item=value}
                <!-- {$value|print_r} -->
                {if $value.child-service ne '1'}
           <option value="{$value|escape|lower|replace:'&':'and'|replace:' ':'-'}">{$value}</option>
                {/if}
           {/foreach}
Check the html source of the page to see what's in the comments
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: LISE: using field definitions in the filter module

Post by blackrain »

So does that mean that the field defs are not accessible in the filter templates?

I only require the dropdown to show some of the values as the LISEServices Modules is used in 2 sections of the site and both need separate content.

the values returned by {$value|print_r} are sectionname and 1, not sure what the 1 is but its there none the less


Thanks for your help
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE: using field definitions in the filter module

Post by Jo Morg »

I'm not entirely sure of what you are trying to do. I know for a fact that LISE has a sample template for the search action called filter that works as expected, and which can be tweaked as needed. No javascript used.... and the results are returned already filtered by the parameters\fields used in the search form. It has been used in multiple sites already effectively. If that is not what you are trying to do then I am missing something from your original post...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: LISE: using field definitions in the filter module

Post by blackrain »

Hi Jo Morg,

The filter I am using is an on-page filter (using javascript to return matching people)

There are 3 filters Service, Specialism and Location. Each dropdown removes the people that do not fit the criteria.

I too have used the filter system to return people for each dropdown with a call to the server, but I am not calling the server each time in this case as all people are loaded on first call.

My issue is that on the services dropdown there are currently 7 possible options and I only want to show the top 3 as all the others are classed as child services to the parent services.

I have created a 'child service' check box in the hope that I can use this to remove the 'child services' from the filter dropdown and only give the user an option of three services to choose from.

I hope this help clarify my problem.

Thanks

Mark
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE: using field definitions in the filter module

Post by Jo Morg »

blackrain wrote:I have created a 'child service' check box in the hope that I can use this to remove the 'child services' from the filter dropdown and only give the user an option of three services to choose from.
That's a pure Javascript problem... nothing to do with LISE itself... I believe you'll be able to find a solution with some googling ;)
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: LISE: using field definitions in the filter module

Post by blackrain »

The problem I am trying to overcome is the dropdown is auto populated by LISE Instance Item field def and not javascript. I just need a way of accessing the field def values in the filter template.

Code: Select all

{foreach from=$fielddef->values item=value}
               {if $value->child-service ne '1'}
	        <option value="{$value|escape|lower|replace:'&':'and'|replace:' ':'-'}">{$value}</option>
                {/if}
	        {/foreach}
if I knew how to call the 'child-service' value I could filter out those values with an if conditional.

On The LISE template each custom_field_def is accessible via;

Code: Select all

{$item->fielddefs.alias_of_field_def.value}
just not sure if this is possible or what the correct syntax is.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE: using field definitions in the filter module

Post by Jo Morg »

blackrain wrote:I have created a 'child service' check box in the hope that I can use this to remove the 'child services' from the filter dropdown and only give the user an option of three services to choose from.
And how is that going to work without a server query if not by using Javascript to remove the options from the dropdown dynamically? Unless, again, I'm not understanding what you are trying to do...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: LISE: using field definitions in the filter module

Post by blackrain »

The JavaScript does not make any calls to the server, it just hides the items that do not have the selected class from the dropdown.

I wanted to 'on page load' only show the parent services. i.e. anything not checked as a 'child-service'

Is there any way to get values from the LISEService instance in the Services dropdown in the LISEPeople page.

or do I just hard code it, but this seems like a far from dynamic solution.

Cheers

Mark
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: LISE: using field definitions in the filter module

Post by velden »

So to summarize:

You already have a (full) list of items (people) and now you're using a javascript solution to actually hide items that don't fit the criteria from a filter? Right?

This does not involve LISE at all (the filtering part) if I understand this correctly.

In this case I think it would be best to use a summary template to build the html for the javascript filter. The summary templates have access to all properties of the items.

First loop all items in the summary template and store the needed options/values in a variabele for each filter.

After that loop those variabeles to create the dropdowns.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE: using field definitions in the filter module

Post by Jo Morg »

Ok, I didn't test this but it may work:

Code: Select all

{$do_not_display=['sub-service-1', 'sub-service-2']}{* <--- use the name of the values to omit *}
{foreach from=$fielddefs item=fielddef}
   {if $fielddef.type != 'Categories'}
       <select class="wide select-filter" name="{$actionid}search_{$fielddef->alias}" id="filter_{$fielddef->alias}">
           <option value='all-{$fielddef->name|escape|lower|replace:' ':'-'}'>{$fielddef->name}</option>
           {foreach from=$fielddef->values item=value}
              {if $fielddef->alias == 'Service' && !in_array($value, $do_not_display)} 
           <option value="{$value|escape|lower|replace:'&':'and'|replace:' ':'-'}">{$value}</option>
                {/if}
           {/foreach}
       </select>
   {/if}
{/foreach}
You may need to tweak a bit to fit the field name and values to omit though....
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: LISE: using field definitions in the filter module

Post by blackrain »

Hi Jo Morg,

you are on fire today!

top solution, that helps me so much.

made a minor change as the other dropdowns stopped working but only a minor change
{if $fielddef->alias == 'Service' && !in_array($value, $do_not_display)}
became

Code: Select all

{if !in_array($value, $do_not_display)}
This works a treat, as the conditional is inside the foreach loop the default 'Service' is unaffected

you have been a great help, thank you.

Mark
Locked

Return to “Modules/Add-Ons”