1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31:
32: class Mage_Adminhtml_Block_Customer_Edit_Renderer_Region
33: extends Mage_Adminhtml_Block_Abstract
34: implements Varien_Data_Form_Element_Renderer_Interface
35: {
36: 37: 38: 39: 40: 41:
42: public function render(Varien_Data_Form_Element_Abstract $element)
43: {
44: if ($country = $element->getForm()->getElement('country_id')) {
45: $countryId = $country->getValue();
46: }
47: else {
48: return $element->getDefaultHtml();
49: }
50:
51: $regionId = $element->getForm()->getElement('region_id')->getValue();
52:
53: $html = '<tr>';
54: $element->setClass('input-text');
55: $element->setRequired(true);
56: $html .= '<td class="label">' . $element->getLabelHtml() . '</td><td class="value">';
57: $html .= $element->getElementHtml();
58:
59: $selectName = str_replace('region', 'region_id', $element->getName());
60: $selectId = $element->getHtmlId() . '_id';
61: $html .= '<select id="' . $selectId . '" name="' . $selectName
62: . '" class="select required-entry" style="display:none">';
63: $html .= '<option value="">' . Mage::helper('customer')->__('Please select') . '</option>';
64: $html .= '</select>';
65:
66: $html .= '<script type="text/javascript">' . "\n";
67: $html .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $regionId.'");' . "\n";
68: $html .= 'new regionUpdater("' . $country->getHtmlId() . '", "' . $element->getHtmlId()
69: . '", "' . $selectId . '", ' . $this->helper('directory')->getRegionJson() . ');' . "\n";
70: $html .= '</script>' . "\n";
71:
72: $html .= '</td></tr>' . "\n";
73:
74: return $html;
75: }
76: }
77: