From 3ac07020945751505b06d4acc358575e92860e0e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 22 Aug 2024 10:13:22 +0100 Subject: [PATCH 1/3] Fixed #15344 - make select2 for countries freeform-ish Signed-off-by: snipe --- resources/lang/en-US/localizations.php | 5 ++++- resources/macros/macros.php | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) 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 .= ''; - // 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 .= ' '; + // Loop through the countries configured in the localization file + $select .= ' '; + + } + + // 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 .= ' '; } $select .= ''; From 305dc049a498c913caacdd6f2c21f4320b9c9e52 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 22 Aug 2024 11:01:28 +0100 Subject: [PATCH 2/3] Added asterisk help text Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 + resources/views/partials/forms/edit/address.blade.php | 1 + resources/views/users/edit.blade.php | 2 ++ resources/views/users/view.blade.php | 4 +++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index a60f0dedfd..4ebf1b8977 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -561,5 +561,6 @@ return [ 'remaining_var' => ':count Remaining', 'label' => 'Label', 'import_asset_tag_exists' => 'An asset with the asset tag :asset_tag already exists and an update was not requested. No change was made.', + 'countries_manually_entered_help' => 'Values with an asterisk (*) were manually entered and do not match existing ISO 3166 dropdown values', ]; diff --git a/resources/views/partials/forms/edit/address.blade.php b/resources/views/partials/forms/edit/address.blade.php index c68ecaa8c2..893bd01339 100644 --- a/resources/views/partials/forms/edit/address.blade.php +++ b/resources/views/partials/forms/edit/address.blade.php @@ -35,6 +35,7 @@ {{ Form::label('country', trans('general.country'), array('class' => 'col-md-3 control-label')) }}
{!! Form::countries('country', old('country', $item->country), 'select2') !!} +

{{ trans('general.countries_manually_entered_help') }}

{!! $errors->first('country', '') !!}
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 5f0246d022..1c23b76823 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -451,6 +451,8 @@
{!! Form::countries('country', old('country', $user->country), 'col-md-12 select2') !!} + +

{{ trans('general.countries_manually_entered_help') }}

{!! $errors->first('country', '') !!}
diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 8fbed865ee..e2397ebe86 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -197,7 +197,9 @@ {{ trans('admin/users/general.print_assigned') }} @else - + @endif @endcan From 5efddf6f5b287f83295e5bde066e7a5a707215e6 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 22 Aug 2024 11:01:39 +0100 Subject: [PATCH 3/3] Allow clear on country dropdown Signed-off-by: snipe --- resources/macros/macros.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 1cc754b7cf..5d0813115e 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -35,7 +35,7 @@ Form::macro('countries', function ($name = 'country', $selected = null, $class = // Pull the autoglossonym array from the localizations translation file $countries_array = trans('localizations.countries'); - $select = ''; $select .= ''; foreach ($countries_array as $abbr => $country) { @@ -46,13 +46,13 @@ Form::macro('countries', function ($name = 'country', $selected = null, $class = } // Loop through the countries configured in the localization file - $select .= ' '; + $select .= ' '; } // 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 .= ' '; + $select .= ' '; } $select .= '';