Form.countrySelect ViewHelper <f:form.countrySelect>

Renders a <select> tag with all available countries as options.

Examples

Basic usage

<f:form.countrySelect name="country" value="{defaultCountry}" />
Copied!

Output:

<select name="country">
  <option value="BE">Belgium</option>
  <option value="FR">France</option>
  ....
</select>
Copied!

Prioritize countries

Define a list of countries which should be listed as first options in the form element:

  <f:form.countrySelect
    name="country"
    value="AT"
    prioritizedCountries="{0: 'DE', 1: 'AT', 2: 'CH'}"
  />

Additionally, Austria is pre-selected.
Copied!

Display another language

A combination of optionLabelField and alternativeLanguage is possible. For instance, if you want to show the localized official names but not in your default language but in French. You can achieve this by using the following combination:

<f:form.countrySelect
  name="country"
  optionLabelField="localizedOfficialName"
  alternativeLanguage="fr"
  sortByOptionLabel="true"
/>
Copied!

Bind an object

You can also use the "property" attribute if you have bound an object to the form. See <f:form> for more documentation.

Source code

Go to the source code of this ViewHelper: Form\CountrySelectViewHelper.php (GitHub).

Arguments

The following arguments are available for the form.countrySelect ViewHelper:

additionalAttributes

additionalAttributes
Type
array
Additional tag attributes. They will be added directly to the resulting HTML tag.

alternativeLanguage

alternativeLanguage
Type
string
If specified, the country list will be shown in the given language.

aria

aria
Type
array
Additional aria-* attributes. They will each be added with a "aria-" prefix.

data

data
Type
array
Additional data-* attributes. They will each be added with a "data-" prefix.

errorClass

errorClass
Type
string
Default
'f3-form-error'
CSS class to set if there are errors for this ViewHelper

excludeCountries

excludeCountries
Type
array
Default
array ( )
Array with country codes that should not be shown.

multiple

multiple
Type
boolean
Default
false
If set multiple options may be selected.

name

name
Type
string
Name of input tag

onlyCountries

onlyCountries
Type
array
Default
array ( )
If set, only the country codes in the list are rendered.

optionLabelField

optionLabelField
Type
string
Default
'localizedName'
If specified, will call the appropriate getter on each object to determine the label. Use "name", "localizedName", "officialName" or "localizedOfficialName"

prependOptionLabel

prependOptionLabel
Type
string
If specified, will provide an option at first position with the specified label.

prependOptionValue

prependOptionValue
Type
string
If specified, will provide an option at first position with the specified value.

prioritizedCountries

prioritizedCountries
Type
array
Default
array ( )
A list of country codes which should be listed on top of the list.

property

property
Type
string
Name of Object Property. If used in conjunction with <f:form object="...">, the "name" property will be ignored, while "value" can be used to specify a default field value instead of the object property value.

required

required
Type
boolean
Default
false
If set no empty value is allowed.

sortByOptionLabel

sortByOptionLabel
Type
boolean
Default
false
If true, List will be sorted by label.

value

value
Type
mixed
Value of input tag