Drop-down Choices on the Profile Field vs. Profile Search Form

Home Forums BP Profile Search Forum Drop-down Choices on the Profile Field vs. Profile Search Form

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #10671 Reply
    Daniel Forteza
    Guest

    Hi Andrea, hope you’re doing well.

    Is it possible for the choices on the ‘drop-down select box’ from the Profile Field to be chosen more than just one choice on its corresponding Profile Search form?

    I got this ‘drop-down select box’ of “country” wherein users can only input/select one which is correct since they only have one country.

    But on its corresponding Profile Search form, I want users to search other users by one or more than one country. So If I want to search for users coming from the US, UK, and Canada, I can get the result in just one search click instead of three.

    Currently, I can only search for one country at a time by using the ‘Drop-down select box’ field. Here is the snapshot from its Profile search form: https://prnt.sc/sdz6c1

    There is also an option on the Profile field called ‘Multi-Select Box’ which users can input more than one choices on the Profile Field (which user can also choose more than one on its corresponding Profile Search form), but I don’t prefer using ‘Multi-Select Box’ field because in my case it has to be only one country to begin with.

    I hope it makes sense.

    Thank you for your time.

    #10672 Reply
    Daniel Forteza
    Guest

    And by the way, if I choose “is one of” on its search mode, it becomes checkboxes like this: https://prnt.sc/sdzgd6 — which is what I wanted and I can now select more than one choices but it’s just too long and doesn’t look good on my site (since there are 200+ countries). I still prefer it to be drop-down box but can select multiple choices on the Profile search form.

    #10673 Reply
    andrea
    Keymaster

    Hi Daniel,

    You can keep the search mode ‘is one of’, and change the check-boxes display adding this code to bp-custom.php:

    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
    	if ($f->code == 'field_57' && $f->display == 'checkbox')
    	{
    		$f->display = 'multiselectbox';
    		$f->multiselect_size = 10;
    	}
    }

    Replace 57 with the actual ID of your field, and 10 with the desired size of your multi-select box.

    #10674 Reply
    Daniel Forteza
    Guest

    Hi Andrea,

    I just added the code and change the field ID but it somehow broke my site: https://prnt.sc/se55ir

    The checkboxes didn’t change to multi-select or dropdown box.

    Am I missing something?

    Regards,
    Daniel

    #10675 Reply
    andrea
    Keymaster

    Hi Daniel,

    Does your bp-custom.php start with <?php ?

    <?php
    
    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
    	if ($f->code == 'field_57' && $f->display == 'checkbox')
    	{
    		$f->display = 'multiselectbox';
    		$f->multiselect_size = 10;
    	}
    }
    #10676 Reply
    Daniel Forteza
    Guest

    Hi Andrea,

    It worked!

    Yes, my bp-custom.php starts with <?php

    By the way, what if I have multiple fields to change the display? I tried to copy-paste the same code to my bp-custom.php and just change the field ID: https://prnt.sc/se5v49

    But it broke my site.

    Thank you so much.
    Daniel

    #10677 Reply
    andrea
    Keymaster

    Hi Daniel,

    You can add other fields inside the same function:

    <?php
    
    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
    	if ($f->code == 'field_13' && $f->display == 'checkbox')
    	{
    		$f->display = 'multiselectbox';
    		$f->multiselect_size = 5;
    	}
    	if ($f->code == 'field_574' && $f->display == 'checkbox')
    	{
    		$f->display = 'multiselectbox';
    		$f->multiselect_size = 5;
    	}
    }
    #10678 Reply
    Daniel Forteza
    Guest

    Thank you so much, Andrea.

    You’re the best!

    #10679 Reply
    andrea
    Keymaster

    You’re welcome!

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Drop-down Choices on the Profile Field vs. Profile Search Form
Your information: