Allow clear on country dropdown

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-08-22 11:01:39 +01:00
parent 305dc049a4
commit 5efddf6f5b

View file

@ -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 name="'.$name.'" class="'.$class.'" style="width:100%" '.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_country').'" data-tags="true">';
$select = '<select name="'.$name.'" class="'.$class.'" style="width:100%" '.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_country').'" data-allow-clear="true" data-tags="true">';
$select .= '<option value="" role="option">'.trans('localizations.select_country').'</option>';
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 .= '<option value="'.$selected.'" selected="selected" role="option" aria-selected="true" aria-selected="false">'.$country.'</option> ';
$select .= '<option value="'.$abbr.'" selected="selected" role="option" '.(($selected == $abbr) ? ' 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 .= '<option value="' . $selected . '" selected="selected" role="option" aria-selected="true">' . $selected .' *</option> ';
}
$select .= '</select>';