Skip to content

A free open source IT asset/license management system

Fixed #15344 - make select2 for countries freeform-ish

snipe3ac070209457
diff --git a/resources/lang/en-US/localizations.php b/resources/lang/en-US/localizations.php
index f335ddc1b3..e87af0718e 100644
--- a/resources/lang/en-US/localizations.php
+++ b/resources/lang/en-US/localizations.php
@@ -135,6 +135,7 @@ return [
'EC'=>'Ecuador',
'EE'=>'Estonia',
'EG'=>'Egypt',
+ 'GB-ENG'=>'England',
'ER'=>'Eritrea',
'ES'=>'Spain',
'ET'=>'Ethiopia',
@@ -233,6 +234,7 @@ return [
'NG'=>'Nigeria',
'NI'=>'Nicaragua',
'NL'=>'Netherlands',
+ 'GB-NIR' => 'Northern Ireland',
'NO'=>'Norway',
'NP'=>'Nepal',
'NR'=>'Nauru',
@@ -260,7 +262,7 @@ return [
'RU'=>'Russian Federation',
'RW'=>'Rwanda',
'SA'=>'Saudi Arabia',
- 'UK'=>'Scotland',
+ 'GB-SCT'=>'Scotland',
'SB'=>'Solomon Islands',
'SC'=>'Seychelles',
'SS'=>'South Sudan',
@@ -312,6 +314,7 @@ return [
'VI'=>'Virgin Islands (U.S.)',
'VN'=>'Viet Nam',
'VU'=>'Vanuatu',
+ 'GB-WLS' =>'Wales',
'WF'=>'Wallis And Futuna Islands',
'WS'=>'Samoa',
'YE'=>'Yemen',
diff --git a/resources/macros/macros.php b/resources/macros/macros.php
index 7fefba2aa6..1cc754b7cf 100644
--- a/resources/macros/macros.php
+++ b/resources/macros/macros.php
@@ -32,18 +32,27 @@ Form::macro('countries', function ($name = 'country', $selected = null, $class =
$idclause = (!is_null($id)) ? $id : '';
- $select = '<select name="'.$name.'" class="'.$class.'" style="width:100%" '.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_country').'">';
+ // Pull the autoglossonym array from the localizations translation file
+ $countries_array = trans('localizations.countries');
+
+ $select = '<select name="'.$name.'" class="'.$class.'" style="width:100%" '.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_country').'" data-tags="true">';
$select .= '<option value="" role="option">'.trans('localizations.select_country').'</option>';
- // Pull the autoglossonym array from the localizations translation file
- foreach (trans('localizations.countries') as $abbr => $country) {
+ foreach ($countries_array as $abbr => $country) {
// We have to handle it this way to handle deprecication warnings since you can't strtoupper on null
if ($abbr!='') {
$abbr = strtoupper($abbr);
}
- $select .= '<option value="'.$abbr.'"'.(($selected == $abbr) ? ' selected="selected" role="option" aria-selected="true"' : ' aria-selected="false"').'>'.$country.'</option> ';
+ // Loop through the countries configured in the localization file
+ $select .= '<option value="'.$selected.'" selected="selected" role="option" aria-selected="true" aria-selected="false">'.$country.'</option> ';
+
+ }
+
+ // If the country value doesn't exist in the array, add it as a new option and select it so we don't drop that data
+ if (!in_array($selected, $countries_array)) {
+ $select .= '<option value="' . $selected . '" selected="selected" role="option" aria-selected="true">' . $selected .' '. trans('general.new') .'</option> ';
}
$select .= '</select>';