_info, $field, $default); } protected function _getInfo($name, $value = null, $attribs = null, $options = null, $listsep = null) { $info = parent::_getInfo($name, $value, $attribs, $options, $listsep); $customOptions = ['parentElementId', 'queryUrl', 'mode']; foreach ($customOptions as $infoName => $attrib) { if (is_numeric($infoName)) { $infoName = $attrib; } if (array_key_exists($attrib, $info['attribs'])) { $info[$infoName] = $info['attribs'][$attrib]; unset($info['attribs'][$attrib]); } } $info['other'] = Qs_Array::map($info, ['id', 'name']); $info['name'] = '_' . $info['name']; $info['id'] = '_' . $info['id']; $info['other']['value'] = $info['value']; if ($info['mode'] == SelectOther::MODE_SELECT_OTHER) { $info['options'][self::OTHER] = 'Other'; if (!array_key_exists($info['value'], $options)) { $info['value'] = self::OTHER; } if (array_key_exists('maxlength', $info['attribs'])) { $info['other']['maxlength'] = $info['attribs']['maxlength']; unset($info['attribs']['maxlength']); } } $this->_info = $info; return $info; } public function formSelectOther($name, $value = null, $attribs = null, $options = null, $listsep = "
\n") { global $doc; $html = parent::formSelect($name, $value, $attribs, $options, $listsep); $html .= $this->renderTextInput($name, $this->getInfo('other[value]')); $doc->addScript('js/lib/form/element/selectOther.js'); $doc->addInitObject('lib.form.element.SelectOther', [[ 'id' => $this->getInfo('other[id]'), 'selectId' => $this->getInfo('id'), 'parentElementId' => $this->getInfo('parentElementId'), 'hasOtherInput' => $this->getInfo('mode') == SelectOther::MODE_SELECT_OTHER, 'OTHER' => self::OTHER, 'queryUrl' => $this->getInfo('queryUrl'), ]]); return $html; } protected function renderTextInput($name, $value) { $attribs = $this->getInfo('other'); if ($value != self::OTHER && array_key_exists($value, $this->getInfo('options')) || SelectOther::MODE_SELECT == $this->getInfo('mode') ) { $attribs['style'] = 'display:none'; } return $this->view->formText($name, $value, $attribs); } }