'country-state-name', ]; if ($isDropdownActive) { $info['options'] = array_merge( $info['defaultOptions'], Qs_Array::fetchPairs($info['states'][$info['countryId']]) ); $info['inputValue'] = ''; $info['inputAttribs']['class'] = Html::addClass($info['inputAttribs']['class'], 'hidden'); $info['inputAttribs']['disabled'] = 'disabled'; } else { $info['attribs']['class'] = Html::addClass($info['attribs']['class'], 'hidden'); $info['attribs']['disabled'] = 'disabled'; $info['options'] = $info['defaultOptions']; $info['inputValue'] = $value; $info['value'] = ''; } if (']' === substr($info['name'], -1)) { $info['countryElement'] = preg_replace('/\[[^\]]+\]$/', '[' . $info['countryElement'] . ']', $info['name']); $info['countryElementId'] = $this->nameToId($info['countryElement']); } else { $info['countryElementId'] = $info['countryElement']; } $info['inputAttribs']['id'] = $this->nameToId($info['name'] . '-input'); return $info; } protected function nameToId($name) { return trim(strtr($name, ['[' => '-', ']' => '']), '-'); } public function formCountryState($name, $value = null, $attribs = null, $options = null, $listsep = "
\n") { $info = $this->_getInfo($name, $value, $attribs, $options, $listsep); // dropdown variables $name = $id = $value = $attribs = $options = $listsep = $disable = $escape = null; // input variables $inputValue = $inputAttribs = null; // javascript variables $defaultOptions = $states = $countryId = $countryElement = $countryElementId = null; extract($info); $html = $this->view->formSelect($name, $value, $attribs, $options, $listsep); $html .= $this->view->formText($name, $inputValue, $inputAttribs); /** @var App_Doc_Site $doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/qs/form/element/countryState.js'); $options = [ 'id' => $id . '-element', 'states' => $states, 'emptyTitle' => !empty($defaultOptions) ? current($defaultOptions) : null, 'nodes' => [ 'dropdown' => '#' . $id, 'input' => '#' . $inputAttribs['id'], 'countryElement' => '#' . $countryElementId, ], ]; $doc->addInitObject('qs.form.element.CountryState', [$options]); return $html; } }