GreatPotato, on 11 January 2012 - 04:40 AM, said:
I understand why the state selector is in the format it is in, eg:
<option value="#">England/Suffolk</option>
But it would look so much better if it used option groups
<optgroup label="England">
<option value="#">Suffolk</option>
Especially as it would mean people could type "S" on their keyboard to get to Suffolk as per this example.
Thoughts?
I am unfamiliar with the "states" out there... but was this frontend? or backend?
If it were frontend, couldn't you process the array of options, prior to building the select... do something like explode and create an array of arrays from that.
Then it should be as easy as looping through one array for the optgroups, and the child arrays for the options.
EDIT:
I went and enabled the UK, then threw together a quick fix for you. This will replace shop:state_selector...
<select autocomplete="off" id="<?= h($control_id) ?>" name="<?= $control_name ?>">
<?
$opt = false;
$fresh = false;
foreach ($states as $state):
$tup = explode('/',$state->name);
if(isset($tup[1])){
if($tup[0] !== $opt){
if($opt)
echo "</optgroup>";
$opt = $tup[0];
$fresh = true;
}
$state->name = $tup[1];
}
if($opt && $fresh){
echo "<optgroup label='" . h($opt) . "'>";
$fresh = false;
}
?>
<option <?= option_state($current_state, $state->id) ?> value="<?= h($state->id) ?>"><?= h($state->name) ?></option>
<? endforeach ?>
</select>
sorry it is kinda ugly. gonna have to revisit this before it is set.