All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Searching multiple custom fields in one select

Danielle LeComte 14 Apr 2015 18:04 question, complete

Hey Low! Hope you are well.

I'd like to try and search multiple custom fields, using one select tag. Is this possible?

For instance...


<label for="member_profile_specialties">Specialties</label>
<select name="search:specialties" id="low_search_specialties" class="select">
<option value="">-- Choose --</option>
{exp:low_options:member_profile_specialties parse="inward"}
{if option:group != ''}<optgroup label="{option:group}">{/if}
{options}
<option value="{option:value}"{if option:value == low_search_search:specialties} selected{/if}>
{option:label}
</option>
{/options}
{if option:group != ''}</optgroup>{/if}
{/exp:low_options:member_profile_specialties}

{exp:low_options:member_profile_trainer_certs parse="inward"}
{if option:group != ''}<optgroup label="{option:group}">{/if}
{options}
<option value="{option:value}"{if option:value == low_search_search:specialties} selected{/if}>
{option:label}
</option>
{/options}
{if option:group != ''}</optgroup>{/if}
{/exp:low_options:member_profile_trainer_certs}

{exp:low_options:member_profile_group_exercise_sp parse="inward"}
{if option:group != ''}<optgroup label="{option:group}">{/if}
{options}
<option value="{option:value}"{if option:value == low_search_search:specialties} selected{/if}>
{option:label}
</option>
{/options}
{if option:group != ''}</optgroup>{/if}
{/exp:low_options:member_profile_group_exercise_sp}

{exp:low_options:member_profile_nutrition_specs parse="inward"}
{if option:group != ''}<optgroup label="{option:group}">{/if}
{options}
<option value="{option:value}"{if option:value == low_search_search:specialties} selected{/if}>
{option:label}
</option>
{/options}
{if option:group != ''}</optgroup>{/if}
{/exp:low_options:member_profile_nutrition_specs}
</select>


Thanks!
Danielle

Replies

  1. Low 14 Apr 2015 18:11

    If you're *only* using that select, you could create a collection where the different fields you want to target have weight, and then use name="keywords" in the select.

    If you are using keywords, then you'd need to use JavaScript to change the name="" attribute of the select-element based on the selected value.

  2. Danielle LeComte 14 Apr 2015 18:16

    Thx - yeah, I have a keywords input field already in the same form.

    Shoot!

  3. Low 14 Apr 2015 18:18

    Using JS shouldn't be too hard. Use a data-name="search:field_name" attribute on each option, then use that to change the name="" param on the select onchange.

  4. Danielle LeComte 14 Apr 2015 18:19

    Ok - gonna try that next.

  5. Danielle LeComte 14 Apr 2015 18:26

    Am I just changing the name of the select when an option is chosen? Doesn't seem to return accurate results.

  6. Low 14 Apr 2015 18:35

    Yeah. Something like this: https://gist.github.com/low/3fe5aefc7...

  7. Danielle LeComte 14 Apr 2015 18:39

    Oh, ok - thank you. I was changing the name attribute incorrectly. You are the man! Appreciate you!