/** * @inheritDoc */ public function labelEx($model, $attribute, $htmlOptions = array()) { if (!$this->qualifyNames && !isset($htmlOptions['for'])) { $htmlOptions['for'] = \CHtml::getIdByName($attribute); } return parent::labelEx($model, $attribute, $htmlOptions); }
/** * @param array $widgetOptions Widget options. * @covers ::run * @dataProvider testRun_FieldRendering_Provider */ public function testRun_FieldRendering($widgetOptions) { $widget = $this->makeWidget(); foreach ($widgetOptions as $option => $value) { $widget->{$option} = $value; } $widgetOutput = $this->runAndCapture($widget); $value = isset($widgetOptions['model']) ? $widgetOptions['model']->login : $widgetOptions['value']; if (isset($widgetOptions['model'])) { $name = CHtml::activeName($widgetOptions['model'], $widgetOptions['attribute']); } elseif (isset($widgetOptions['htmlOptions']['name'])) { $name = $widgetOptions['htmlOptions']['name']; } else { $name = $widgetOptions['name']; } if (isset($widgetOptions['model'])) { $id = CHtml::activeId($widgetOptions['model'], $widgetOptions['attribute']); } elseif (isset($widgetOptions['htmlOptions']['id'])) { $id = $widgetOptions['htmlOptions']['id']; } else { $id = CHtml::getIdByName($widgetOptions['name']); } if ($widgetOptions['type'] == Select2::TYPE_TEXT) { $this->assertTag(['tag' => 'input', 'attributes' => ['type' => 'text', 'name' => $name, 'id' => $id, 'value' => $value, 'class' => 'baz']], $widgetOutput); } else { $this->assertTag(['tag' => 'select', 'attributes' => ['name' => $name, 'id' => $id, 'class' => 'baz']], $widgetOutput); $this->assertTag(['tag' => 'option', 'parent' => ['tag' => 'select'], 'attributes' => ['selected' => 'selected', 'value' => $value]], $widgetOutput); } }
function autoComplete($name, $complete_view, $id = '', $value = '') { $url = is_array($complete_view) ? $complete_view : array($complete_view); $dom_id = CHtml::getIdByName($name); echo CHtml::hiddenField($name, $id, array('id' => $dom_id)); $this->widget('zii.widgets.jui.CJuiAutoComplete', array('name' => $dom_id . '_autocomplete', 'sourceUrl' => $url, 'options' => array('select' => "js:function(event, ui) {\n \$('#{$dom_id}').val(ui.item.id);\n }"), 'value' => $value)); }
public static function radioButtonList($name, $select, $data, $htmlOptions = array()) { $template = isset($htmlOptions['template']) ? $htmlOptions['template'] : '{input} {label}'; $separator = isset($htmlOptions['separator']) ? $htmlOptions['separator'] : "<br/>\n"; unset($htmlOptions['template'], $htmlOptions['separator']); $labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array(); unset($htmlOptions['labelOptions']); $items = array(); $baseID = CHtml::getIdByName($name); $id = 0; foreach ($data as $value => $item) { $checked = !strcmp($value, $select); $htmlOptions['value'] = $value; $labelOptions['id'] = $baseID . '_label_' . $id; $htmlOptions['id'] = $baseID . '_' . $id++; $labelOptions['title'] = $item['title']; $htmlOptions['class'] = 'ui-icon ui-state-default ' . $item['class']; $option = CHtml::radioButton($name, $checked, $htmlOptions); if (!empty($item['icon'])) { $item['caption'] = '<span style="float:left;" class="ui-icon ' . $item['icon'] . '"> ' . $item['caption'] . '</span>' . $item['caption']; } $label = CHtml::label($item['caption'], $htmlOptions['id'], $labelOptions); $items[] = strtr($template, array('{input}' => $option, '{label}' => $label)); } return CHtml::tag('span', array('id' => $baseID), implode($separator, $items)); }
/** * Runs the widget. * This method registers all needed client scripts and renders * the multiple file uploader. */ public function run() { if ($this->name !== null) { $name = $this->name; } else { if (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } else { throw new CException(Yii::t('yii', 'CMultiFileUpload.name is required.')); } } if (substr($name, -2) !== '[]') { $name .= '[]'; } if (($id = $this->getId(false)) === null) { if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $id = CHtml::getIdByName($name); } } $this->htmlOptions['id'] = $id; $this->registerClientScript(); echo CHtml::fileField($name, '', $this->htmlOptions); }
/** * Renders an HTML label for a model attribute. * @param CModel $parentModel the parent data model * @param string $attributedPath the attribute or path to related model attribute * @param array $htmlOptions additional HTML attributes. * @return string the generated label tag */ public function labelEx($parentModel, $attributedPath, $htmlOptions = array()) { list($model, $attribute, $htmlOptions) = self::resolveArgs($parentModel, $attributedPath, $htmlOptions); $htmlOptions['for'] = CHtml::getIdByName($htmlOptions['name']); if (!isset($htmlOptions['label']) && ($label = self::resolveLabel($parentModel, $attributedPath)) !== null) { $htmlOptions['label'] = $label; } return parent::labelEx($model, $attribute, $htmlOptions); }
public function init() { parent::init(); $this->paramLink = array('id_field' => CHtml::getIdByName($this->fieldId), 'multileSelect' => $this->multiSelect ? 1 : 0); if (!$this->dialogZone) { $this->idZone = array('id' => 'showJobDialog', 'class' => 'ajaxlink'); $this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog'); } else { $this->paramLink['id_dialog'] = $this->dialogZone; $this->idZone = array('id' => $this->dialogZone . "-show", 'class' => 'ajaxlink'); $this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#dialog'); } $this->link = $this->controller->createUrl('artist/popupList', $this->paramLink); $this->htmlOptions['readonly'] = 'readonly'; }
public function run() { $cs = Yii::app()->getClientScript(); $textAreaOptions = $this->gettextareaOptions(); $textAreaOptions['name'] = CHtml::resolveName($this->model, $this->name); $this->id = $textAreaOptions['id'] = CHtml::getIdByName($textAreaOptions['name']); echo CHtml::activeTextArea($this->model, $this->name, $textAreaOptions); $properties_string = CJavaScript::encode($this->getKeProperties()); $js = <<<EOF KindEditor.ready(function(K) { \tvar editor_{$this->id} = K.create('#{$this->id}', {$properties_string} \t); }); EOF; $cs->registerScript('KE' . $this->name, $js, CClientScript::POS_HEAD); }
public function init() { parent::init(); $this->paramLink = array('id_field' => CHtml::getIdByName($this->fieldId), 'name_field' => CHtml::getIdByName($this->fieldName)); if (!$this->dialogZone) { $this->idZone = array('id' => 'showJobDialog', 'class' => 'ajaxlink'); $this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog'); } else { $this->paramLink['id_dialog'] = $this->dialogZone; $this->idZone = array('id' => $this->dialogZone . "-show", 'class' => 'ajaxlink'); /*$this->updateZone = array( 'onclick'=>'$("#'.$this->dialogZone.'").dialog("open"); return false;', 'update'=>'#'.$this->dialogZone );*/ $this->updateZone = array('onclick' => '$("#jobDialog").dialog("open"); return false;', 'update' => '#jobDialog'); //echo "<div id='$this->dialogZone'></div>"; } $this->link = $this->controller->createUrl('artist/popupList', $this->paramLink); $this->htmlOptions['readonly'] = 'readonly'; }
/** * Resolves name and ID of the input. Source property of the name and/or source property of the attribute * could be customized by specifying first and/or second parameter accordingly. * @param string $nameProperty class property name which holds element name to be used. This parameter * is available since 1.1.14. * @param string $attributeProperty class property name which holds model attribute name to be used. This * parameter is available since 1.1.14. * @return array name and ID of the input: array('name','id'). * @throws CException in case model and attribute property or name property cannot be resolved. */ protected function resolveNameID($nameProperty = 'name', $attributeProperty = 'attribute') { if ($this->{$nameProperty} !== null) { $name = $this->{$nameProperty}; } elseif (isset($this->htmlOptions[$nameProperty])) { $name = $this->htmlOptions[$nameProperty]; } elseif ($this->hasModel()) { $name = CHtml::activeName($this->model, $this->{$attributeProperty}); } else { throw new CException(Yii::t('zii', '{class} must specify "model" and "{attribute}" or "{name}" property values.', array('{class}' => get_class($this), '{attribute}' => $attributeProperty, '{name}' => $nameProperty))); } if (($id = $this->getId(false)) === null) { if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $id = CHtml::getIdByName($name); } } return array($name, $id); }
/** * @return array the name and the ID of the input. * @throws \foundation\exception\InvalidConfigException */ protected function resolveNameID() { if ($this->name !== null) { $name = $this->name; } elseif (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } elseif ($this->hasModel()) { $name = \CHtml::activeName($this->model, $this->attribute); } else { throw new InvalidConfigException(\Yii::t('yii', '{class} must specify "model" and "attribute" or "name" property values.', array('{class}' => get_class($this)))); } if (($id = $this->getId(false)) === null) { if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $id = \CHtml::getIdByName($name); } } return array($name, $id); }
public function init() { parent::init(); $idTxt = CHtml::getIdByName($this->fieldName); $idById = CHtml::getIdByName($this->fieldId); Yii::app()->getClientScript()->registerCssFile(Yii::app()->theme->baseUrl . "/css/jquery.autocomplete.css"); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/jquery.autocomplete.js"); $link = Yii::app()->createUrl("artist/autoComplete"); $script = <<<EOD \t \$(document).ready(function() { \t \t \$('#{$idTxt}').autocomplete('{$link}', { \t\t\t\twidth: 260, \t\t\t\tmatchContains: true, \t\t\t\tmustMatch: true, \t\t\t\tselectFirst: true \t\t\t}); \t\t\t\$("#{$idTxt}").result(function(event, data, formatted) { \t\t\t\t\$("#{$idTxt}").val(data[0]); \t\t\t\t\$("#{$idById}").val(data[1]); \t\t\t}); \t }); EOD; Yii::app()->clientScript->registerScript("artist-auto", $script, CClientScript::POS_HEAD); }
public function init() { $this->id = CHtml::getIdByName($this->name); parent::init(); $this->publishAssets(); }
/** * @dataProvider providerGetIdByName * * @param string $text * @param string $assertion */ public function testGetIdByName($text, $assertion) { $this->assertEquals($assertion, CHtml::getIdByName($text)); }
protected function resolveID($attr) { $name = CHtml::activeName($this->model, $attr); $id = CHtml::getIdByName($name); return $id; }
/** * Generates a radio button list. * @param string $name name of the radio button list. * @param mixed $select selection of the radio buttons. * @param array $data $data value-label pairs used to generate the radio button list. * @param array $htmlOptions additional HTML attributes. * @return string the generated list. */ public static function radioButtonList($name, $select, $data, $htmlOptions = array()) { $inline = \bootstrap\helpers\BSArray::popValue('inline', $htmlOptions, false); $separator = \bootstrap\helpers\BSArray::popValue('separator', $htmlOptions, ' '); $container = \bootstrap\helpers\BSArray::popValue('container', $htmlOptions); $containerOptions = \bootstrap\helpers\BSArray::popValue('containerOptions', $htmlOptions, array()); $labelOptions = \bootstrap\helpers\BSArray::popValue('labelOptions', $htmlOptions, array()); $items = array(); $baseID = $containerOptions['id'] = \bootstrap\helpers\BSArray::popValue('baseID', $htmlOptions, parent::getIdByName($name)); $id = 0; foreach ($data as $value => $label) { $checked = !strcmp($value, $select); $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; if ($inline) { $htmlOptions['label'] = $label; self::addCssClass('radio-inline', $labelOptions); $htmlOptions['labelOptions'] = $labelOptions; $items[] = self::radioButton($name, $checked, $htmlOptions); } else { $option = self::radioButton($name, $checked, $htmlOptions); self::addCssClass('radio', $labelOptions); $items[] = self::label($option . ' ' . $label, false, $labelOptions); } } $inputs = implode($separator, $items); return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs; }
/** * Renders an input list. * * @param boolean $checkbox flag that indicates if the list is a checkbox-list. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the input list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * * @since 0.9.5 */ protected function inputsList($checkbox, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $select = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; $template = isset($htmlOptions['template']) ? $htmlOptions['template'] : '<label class="{labelCssClass}">{input}{label}</label>'; $container = isset($htmlOptions['container']) ? $htmlOptions['container'] : ''; unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['hint']); if ($checkbox && substr($name, -2) !== '[]') { $name .= '[]'; } $checkAllLast = ''; if (isset($htmlOptions['checkAll'])) { $checkAllLabel = $htmlOptions['checkAll']; $checkAllLast = isset($htmlOptions['checkAllLast']) && $htmlOptions['checkAllLast']; } unset($htmlOptions['checkAll'], $htmlOptions['checkAllLast']); $labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array(); unset($htmlOptions['labelOptions']); $items = array(); $baseID = isset($htmlOptions['baseID']) ? $htmlOptions['baseID'] : CHtml::getIdByName($name); unset($htmlOptions['baseID']); $id = 0; $checkAll = true; $method = $checkbox ? 'checkBox' : 'radioButton'; $labelCssClass = $checkbox ? 'checkbox' : 'radio'; if (isset($htmlOptions['inline'])) { $labelCssClass .= ' inline'; unset($htmlOptions['inline']); } foreach ($data as $value => $label) { $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select); $checkAll = $checkAll && $checked; $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $label = CHtml::label($label, $htmlOptions['id'], $labelOptions); $items[] = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); } if (isset($checkAllLabel)) { $htmlOptions['value'] = 1; $htmlOptions['id'] = $id = $baseID . '_all'; $option = CHtml::$method($id, $checkAll, $htmlOptions); $label = CHtml::label($checkAllLabel, $id, $labelOptions); $item = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); if ($checkAllLast) { $items[] = $item; } else { array_unshift($items, $item); } $name = strtr($name, array('[' => '\\[', ']' => '\\]')); $js = <<<EOD jQuery('#{$id}').click(function() { \t\$("input[name='{$name}']").prop('checked', this.checked); }); jQuery("input[name='{$name}']").click(function() { \t\$('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); }); jQuery('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); EOD; /** @var $cs CClientScript */ $cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery'); $cs->registerScript($id, $js); } if (empty($container)) { return $hidden . implode('', $items); } else { return $hidden . CHtml::tag($container, array('id' => $baseID), implode('', $items)); } }
/** * Renders an input list. * @param boolean $checkbox flag that indicates if the list is a checkbox-list. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the input list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * @since 0.9.5 */ protected function inputsList($checkbox, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $select = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; if (isset($htmlOptions['template'])) { $template = $htmlOptions['template']; } else { $template = '<label class="{labelCssClass}">{input}{label}</label>'; } unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['hint']); if ($checkbox && substr($name, -2) !== '[]') { $name .= '[]'; } unset($htmlOptions['checkAll'], $htmlOptions['checkAllLast']); $labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array(); unset($htmlOptions['labelOptions']); $items = array(); $baseID = CHtml::getIdByName($name); $id = 0; $method = $checkbox ? 'checkBox' : 'radioButton'; $labelCssClass = $checkbox ? 'checkbox' : 'radio'; if (isset($htmlOptions['inline'])) { $labelCssClass .= '-inline'; unset($htmlOptions['inline']); } foreach ($data as $value => $label) { $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select); $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $label = CHtml::label($label, $htmlOptions['id'], $labelOptions); $items[] = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); } return $hidden . implode('', $items); }
/** * Generates a check box list. * @param string $name name of the check box list. * @param mixed $select selection of the check boxes. * @param array $data $data value-label pairs used to generate the check box list. * @param array $htmlOptions additional HTML attributes. * @return string the generated list. */ public static function checkBoxList($name, $select, $data, $htmlOptions = array()) { $inline = TbArray::popValue('inline', $htmlOptions, false); $separator = TbArray::popValue('separator', $htmlOptions, ' '); $container = TbArray::popValue('container', $htmlOptions, 'span'); $containerOptions = TbArray::popValue('containerOptions', $htmlOptions, array()); $labelOptions = TbArray::popValue('labelOptions', $htmlOptions, array()); if (substr($name, -2) !== '[]') { $name .= '[]'; } $checkAll = TbArray::popValue('checkAll', $htmlOptions); $checkAllLast = TbArray::popValue('checkAllLast', $htmlOptions); if ($checkAll !== null) { $checkAllLabel = $checkAll; $checkAllLast = $checkAllLast !== null; } $items = array(); $baseID = $containerOptions['id'] = TbArray::popValue('baseID', $htmlOptions, parent::getIdByName($name)); $id = 0; $checkAll = true; foreach ($data as $value => $label) { $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select); $checkAll = $checkAll && $checked; $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; if ($inline) { $htmlOptions['label'] = $label; self::addCssClass('inline', $labelOptions); $htmlOptions['labelOptions'] = $labelOptions; $items[] = self::checkBox($name, $checked, $htmlOptions); } else { self::addCssClass('checkbox', $labelOptions); $option = self::checkBox($name, $checked, $htmlOptions); $items[] = self::label($option . ' ' . $label, false, $labelOptions); } } if (isset($checkAllLabel)) { $htmlOptions['value'] = 1; $htmlOptions['id'] = $id = $baseID . '_all'; $option = self::checkBox($id, $checkAll, $htmlOptions); $item = self::label($option . ' ' . $checkAllLabel, false, $labelOptions); if ($checkAllLast) { $items[] = $item; } else { array_unshift($items, $item); } $name = strtr($name, array('[' => '\\[', ']' => '\\]')); $js = <<<EOD jQuery('#{$id}').click(function() { \tjQuery("input[name='{$name}']").prop('checked', this.checked); }); jQuery("input[name='{$name}']").click(function() { \tjQuery('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); }); jQuery('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); EOD; $cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery'); $cs->registerScript($id, $js); } $inputs = implode($separator, $items); return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs; }
/** * @return array the name and the ID of the drop-down element. */ protected function resolveDropDownNameID() { $ni = array(); if (!empty($this->name)) { $dname = $this->name; } else { if ($this->hasModel()) { $dname = CHtml::activeName($this->model, $this->dropDownAttribute); CHtml::resolveNameID($this->model, $this->dropDownAttribute, $ni); } else { throw new CException(Yii::t('EchMultiSelect.EchMultiSelect', '{class} must specify "model" and "dropDownAttribute" or "name" property values.', array('{class}' => get_class($this)))); } } if (isset($this->dropDownHtmlOptions['id'])) { $id = $this->dropDownHtmlOptions['id']; } else { if (!empty($ni['id'])) { $id = $ni['id']; } else { $id = CHtml::getIdByName($dname); } } return array($dname, $id); }
?> <fieldset> <legend><?php echo CHtml::encode($page->getWikiUid()); ?> </legend> <div class="control-group"> <div class="controls"> <?php echo CHtml::activeTextArea($page, 'content'); ?> </div> </div> <div class="control-group"> <?php echo CHtml::label(Yii::t('wiki', 'Change summary'), CHtml::getIdByName('comment'), array('class' => 'control-label')); ?> <div class="controls"> <?php echo CHtml::textField('comment', $comment); ?> </div> </div> <div class="form-actions"> <?php echo CHtml::submitButton(Yii::t('wiki', 'Save'), array('class' => 'btn btn-primary')); ?> </div> </fieldset> <?php $this->endWidget();
<?php echo Yii::t('wiki', 'Nr.:'); ?> <?php echo CHtml::activeTextField($page, 'page_index'); ?> <br> <?php echo Yii::t('wiki', 'Title:'); ?> <?php echo CHtml::activeTextField($page, 'page_title'); echo CHtml::activeTextArea($page, 'content'); ?> </div> <div> <?php echo CHtml::label(Yii::t('wiki', 'Change summary'), CHtml::getIdByName('comment')); ?> : <?php echo CHtml::textField('comment', $comment); ?> </div> <div> <?php echo CHtml::submitButton(Yii::t('wiki', 'Save')); ?> </div> <?php echo CHtml::endForm();
/** * Renders a radio button. * @return string the rendered content */ protected function radioButton() { $attribute = $this->attribute; echo '<label class="radio" for="' . CHtml::getIdByName(CHtml::resolveName($this->model, $attribute)) . '">'; echo $this->form->radioButton($this->model, $this->attribute, $this->htmlOptions) . PHP_EOL; echo $this->model->getAttributeLabel($attribute); echo $this->getError() . $this->getHint(); echo '</label>'; }
if (!empty($htmlOptions['append-text']) && !empty($layoutColumns['append-text'])) { ?> <div class="large-<?php echo $layoutColumns['append-text']; ?> column collapse end"> <span class="field-info"><?php echo $htmlOptions['append-text']; ?> </span> </div> <?php } ?> </div> <?php } ?> <script type="text/javascript"> $(document).ready(function() { OpenEyes.UI.Widgets.RRuleField( $('#<?php echo @$htmlOptions['id'] ?: CHtml::getIdByName($name); ?> ') ); }); </script>
/** * Renders a list of radio buttons using Button Groups. * @return string the rendered content */ protected function radioButtonGroupsList() { if (isset($this->htmlOptions['for']) && !empty($this->htmlOptions['for'])) { $label_for = $this->htmlOptions['for']; unset($this->htmlOptions['for']); } else { if (isset($this->data) && !empty($this->data)) { $label_for = CHtml::getIdByName(get_class($this->model) . '[' . $this->attribute . '][' . key($this->data) . ']'); } } if (isset($label_for)) { $this->labelOptions = array('for' => $label_for); } echo $this->getLabel(); echo $this->form->radioButtonGroupsList($this->model, $this->attribute, $this->data, $this->htmlOptions); echo $this->getError() . $this->getHint(); }
private function renderItem(OverrideDataItem $item, $htmlOptions = array(), $checked = array()) { $names = $this->getNames(); $options = CMap::mergeArray(array('for' => CHtml::getIdByName($item->getFullName())), $htmlOptions); if (isset($options['class'])) { $options['class'] = 'checkbox ' . $options['class']; } else { $options['class'] = 'checkbox'; } $label = $item->name; echo CHtml::openTag('label', $options); echo isset($names[$label]) ? $label . ' (' . $names[$label] . ')' : $label; echo CHtml::checkBox('OverrideData[data][' . $item->getFullName() . ']', isset($checked[$item->getFullName()])); echo CHtml::closeTag('label'); }
/** * Renders an input list. * @param string $type the input type. Valid types are 'checkbox' and 'radio'. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the radio button list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * @since 0.9.5 */ protected function inputsList($type, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $selection = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['labelOptions']); $items = array(); $baseID = CHtml::getIdByName($name); $id = 0; $method = $type === 'checkbox' ? 'checkBox' : 'radioButton'; foreach ($data as $value => $label) { $checked = !strcmp($value, $selection); $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $items[] = '<label>' . $option . '<span>' . $label . '</span></label>'; } return $hidden . '<ul class="inputs-list"><li>' . implode('</li><li>', $items) . '</li></ul>'; }
/** * Generates a control group with a check box. * @param string $name the input name. * @param bool $checked whether the check box is checked. * @param array $htmlOptions additional HTML attributes. * @return string the generated control group. * @see self::controlGroup */ public static function checkBoxControlGroup($name, $checked = false, $htmlOptions = array()) { $type = self::INPUT_TYPE_CHECKBOX; $layout = BsArray::popValue('formLayout', $htmlOptions, ''); $help = BsArray::popValue('help', $htmlOptions, ''); $helpOptions = BsArray::popValue('helpOptions', $htmlOptions, array()); $color = BsArray::popValue('color', $htmlOptions, false); $groupOptions = BsArray::popValue('groupOptions', $htmlOptions, false); $controlOptions = BsArray::popValue('controlOptions', $htmlOptions, false); $labelOptions = BsArray::popValue('labelOptions', $htmlOptions, array()); $label = isset($htmlOptions['label']) ? $htmlOptions['label'] : $name; unset($htmlOptions['label']); //Checkboxes require different markup to what is generated by BsHtml::createInput() $output = ''; $labelContent = ''; if ($color) { if ($layout === BsHtml::FORM_LAYOUT_HORIZONTAL) { self::addCssClass($color, $groupOptions); } else { self::addCssClass($color, $controlOptions); } } if ($layout === BsHtml::FORM_LAYOUT_HORIZONTAL) { self::addCssClass('form-group', $groupOptions); $output .= parent::openTag('div', $groupOptions); $output .= parent::openTag('div', array('class' => static::$formLayoutHorizontalOffsetClass . ' ' . static::$formLayoutHorizontalControlClass)); $output .= parent::openTag('div', array('class' => 'checkbox')); } else { self::addCssClass('checkbox', $controlOptions); $output .= parent::openTag('div', $controlOptions); } $input = isset($htmlOptions['input']) ? $htmlOptions['input'] : self::createInput($type, $name, $checked, $htmlOptions); $labelContent .= $input; $labelContent .= $label; $labelOptions['for'] = parent::getIdByName($name); if (!empty($help)) { $labelContent .= self::inputHelp($help, $helpOptions); } $output .= parent::tag('label', $labelOptions, $labelContent); $output .= parent::closeTag('div'); //close <div class="checkbox"> if ($layout === BsHtml::FORM_LAYOUT_HORIZONTAL) { $output .= parent::closeTag('div'); //close <div class="col-lg-offset-2"> $output .= parent::closeTag('div'); //close <div class="form-group"> } return $output; }
/** *### .getAppend() * * Returns the id that should be used for the specified attribute * * @param string $attribute the attribute * * @return string the id */ protected function getAttributeId($attribute) { return isset($this->htmlOptions['id']) ? $this->htmlOptions['id'] : CHtml::getIdByName(CHtml::resolveName($this->model, $attribute)); }
/** * Generates a valid HTML ID based for a model attribute. * Note, the attribute name may be modified after calling this method if the name * contains square brackets (mainly used in tabular input) before the real attribute name. * @param CModel $model the data model * @param string $attribute the attribute * @return string the ID generated based on name. */ public static function resolveId($model, $attribute) { return CHtml::getIdByName(CHtml::resolveName($model, $attribute)); }