Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Won't Fix
-
Affects Version/s: 3.0.1
-
Fix Version/s: Unscheduled
-
Component/s: None
-
Labels:None
-
Documentation Required?:None
-
Funding Source:Needs Funding
Description
Whilst trying to tidy up the Country select dropdown, as described at http://issues.civicrm.org/jira/browse/CRM-5227 I found myself needing to group the countries using <optgroup> within the select. Though this is possible with HTML_Quickform2, CiviCRM is currently using HTML_Quickform1, and this feature is unavailable. Whilst looking for a solution, I found http://pear.php.net/bugs/bug.php?id=1283&thanks=3 where HTML_Quickform1 has been hacked to add in the support. I rolled up the said changes into a patch (http://pear.php.net/bugs/bug.php?id=1283&edit=12&patch=add-optgroup-support&revision=1255771468) and applied it to CiviCRM (attached). It seems to work absolutely fine
For reference, this is how I'm using it, in hook_civicrm_buildForm:
// rebuild the country selecter to only contain the UK and select UK by default
foreach(CRM_Core_PseudoConstant::country() as $key => $value) {
if ($key == '1105' || $key == '1226')
else
{ $otherCountries[$key] = $value; } }
$finalCountries = array('' => '- select -') + $topCountries + array(' ---------- ' => $otherCountries);
$form->addElement('select', 'billing_country_id-'. $form->_bltID, ts('Country'), $finalCountries);