LemonStand Forum: State selector to use option groups - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

State selector to use option groups

#1 User is offline   GreatPotato 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 92
  • Joined: 02-August 11

Posted 11 January 2012 - 04:40 AM

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?
0

#2 User is offline   EHLOVader 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 246
  • Joined: 05-May 11

Posted 11 January 2012 - 08:49 PM

View PostGreatPotato, 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.
1

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users