Hello,

I have a text field with select list with the below allowed values of countries which will be required. I want several countries to be at the top, then a space or ---------, then followed by the remaining countries in alphabetical order. But I don't want the blank line between Ireland and Afghanistan to be a selectable choice because I don't want a blank line to be shown as the country, but also want to add the space to separate the countries at the top with the remaining countries below it.

Would anyone be able to help?

Thank you!

USA
UK
Canada
Australia
New Zealand
Ireland

Afghanistan
Albania
Algeria
Angola
Antigua & Barbuda
Argentina
Armenia
Austria
Azerbaijan
Bahrain
Bangladesh
Belarus
Belgium
Benin
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Brazil
Bulgaria
...

Comments

YK85’s picture

I realized there can't even be a blank line in the select list to separate like the example above when the field is *required*
I would really appreciate your help!

cwebster’s picture

I think this is probably the closest you can get with the currently available functionality:

In the settings for your field, right under the "Allowed Values" text area, fold down the "PHP Code" fieldset. Then, paste the following, minus the <?php ?> tags:

return array(
  'USA'=>'USA',
  'UK'=>'UK',
  'Canada'=>'Canada',
  'Australia'=>'Australia',
  'New Zealand'=>'New Zealand',
  'Ireland'=>'Ireland',
  ' ' => array(
    'Afghanistan'=>'Afghanistan',
    'Albania'=>'Albania',
    'Algeria'=>'Algeria',
    'Angola'=>'Angola',
    'Antigua & Barbuda'=>'Antigua & Barbuda',
    'Argentina'=>'Argentina',
    'Armenia'=>'Armenia',
    'Austria'=>'Austria',
    'Azerbaijan'=>'Azerbaijan',
    'Bahrain'=>'Bahrain',
    'Bangladesh'=>'Bangladesh',
    'Belarus'=>'Belarus',
    'Belgium'=>'Belgium',
    'Benin'=>'Benin',
    'Bhutan'=>'Bhutan',
    'Bolivia'=>'Bolivia',
    'Bosnia and Herzegovina'=>'Bosnia and Herzegovina',
    'Botswana'=>'Botswana',
    'Brazil'=>'Brazil',
    'Bulgaria'=>'Bulgaria',
  ),
);

Or you could do something like...

return array(
  'Common' => array(
    'USA'=>'USA',
    'UK'=>'UK',
    'Canada'=>'Canada',
    'Australia'=>'Australia',
    'New Zealand'=>'New Zealand',
    'Ireland'=>'Ireland',
  ),
  'Alphabetical' => array(
    'Afghanistan'=>'Afghanistan',
    'Albania'=>'Albania',
    'Algeria'=>'Algeria',
    'Angola'=>'Angola',
    'Antigua & Barbuda'=>'Antigua & Barbuda',
    'Argentina'=>'Argentina',
    'Armenia'=>'Armenia',
    'Austria'=>'Austria',
    'Azerbaijan'=>'Azerbaijan',
    'Bahrain'=>'Bahrain',
    'Bangladesh'=>'Bangladesh',
    'Belarus'=>'Belarus',
    'Belgium'=>'Belgium',
    'Benin'=>'Benin',
    'Bhutan'=>'Bhutan',
    'Bolivia'=>'Bolivia',
    'Bosnia and Herzegovina'=>'Bosnia and Herzegovina',
    'Botswana'=>'Botswana',
    'Brazil'=>'Brazil',
    'Bulgaria'=>'Bulgaria',
  ),
);
);

Hope that helps.

YK85’s picture

Thanks for your advice. However, it makes the select list like below:

  USA
  UK
  Canada
  Australia
  New Zealand
  Ireland
    Afghanistan
    Albania
    Algeria
    Angola
    Antigua & Barbuda
    Argentina
    Armenia
    Austria
    Azerbaijan
    Bahrain
    Bangladesh
    Belarus
    Belgium
    Benin
    Bhutan
    Bolivia
    Bosnia and Herzegovina
    Botswana
    Brazil
    Bulgaria

What I'm trying to achieve:

USA
UK
Canada
Australia
New Zealand
Ireland
--------------
Afghanistan
Albania
Algeria
Angola
Antigua & Barbuda
Argentina
Armenia
Austria
Azerbaijan
Bahrain
Bangladesh
Belarus
Belgium
Benin
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Brazil
Bulgaria
drup1982’s picture

Same question but I will add the following:
is it possible to make certain value lines non selectable? In the example below can we make Asia and Europe non selectable?
Thanks,

--Asia--
Afghanistan
Albania
Algeria
Angola
Antigua & Barbuda
Argentina
Armenia
Austria
Azerbaijan
Bahrain
Bangladesh
--Europe--
Belarus
Belgium
Benin
Bhutan
Bolivia
Bosnia and Herzegovina

brianbrarian’s picture

For the benefit of anyone still looking for an answer to this question (as I was today) ...

Setting the key of the non-selectable item to NULL appears to work.

return array(
  NULL => '---- Select ----',
  'This' => 'This',
  'That' => 'That',
  'The Other' => 'The Other',
);