Skip to content

A free open source IT asset/license management system

Migrate countries macro on user page

Marcus Moorefa6adaa1554e
diff --git a/resources/views/blade/input/country-select.blade.php b/resources/views/blade/input/country-select.blade.php
new file mode 100644
index 0000000000..03caf18fce
--- /dev/null
+++ b/resources/views/blade/input/country-select.blade.php
@@ -0,0 +1,35 @@
+@props([
+ 'name' => 'country',
+ 'selected' => null,
+])
+
+@php
+ $countries_array = trans('localizations.countries');
+@endphp
+
+<select
+ name="{{ $name }}"
+ {{ $attributes->merge(['class' => 'select2']) }}
+ aria-label="{{ $name }}"
+ data-placeholder="{{ trans('localizations.select_country') }}"
+ data-allow-clear="true"
+>
+ @foreach($countries_array as $abbreviation => $country)
+ @php
+ // We have to handle it this way to handle deprecation warnings since you can't strtoupper on null
+ if ($abbreviation!='') {
+ $abbreviation = strtoupper($abbreviation);
+ }
+ @endphp
+
+ <option value="{{ $abbreviation }}" {{ $selected === $abbreviation ? 'selected' : '' }}>
+ {{ $country }}
+ </option>
+ @endforeach
+
+ {{-- 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 (!array_key_exists($selected, $countries_array)) {
+ <option value="{{ e($selected) }}" selected="selected" role="option" aria-selected="true"> {{ e($selected) }} *</option> ';
+ @endif
+
+</select>
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php
index 1db8a6052d..ff4826799e 100755
--- a/resources/views/users/edit.blade.php
+++ b/resources/views/users/edit.blade.php
@@ -502,7 +502,11 @@
<div class="form-group{{ $errors->has('country') ? ' has-error' : '' }}">
<label class="col-md-3 control-label" for="country">{{ trans('general.country') }}</label>
<div class="col-md-6">
- {!! Form::countries('country', old('country', $user->country), 'col-md-12 select2') !!}
+ <x-input.country-select
+ name="country"
+ :selected="old('country', $user->country)"
+ class="col-md-12"
+ />
<p class="help-block">{{ trans('general.countries_manually_entered_help') }}</p>
{!! $errors->first('country', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}