/** * @inheritdoc */ public function run() { list($name, $id) = $this->resolveNameID(); if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $this->htmlOptions['id'] = $id; } if (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } if ($this->type == static::TYPE_TEXT) { if ($this->hasModel()) { echo \CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions); } else { echo \CHtml::textField($name, $this->value, $this->htmlOptions); } } elseif ($this->type == static::TYPE_SELECT) { if ($this->hasModel()) { echo \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } else { echo \CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions); } } else { throw new \CException("Invalid field type '{$this->type}'"); } $options = !empty($this->options) ? \CJavaScript::encode($this->options) : ''; $script = "jQuery('#{$id}').select2({$options})"; foreach ($this->events as $event => $handler) { $script .= ".on('{$event}'," . \CJavaScript::encode($handler) . ")"; } $script .= ';'; \Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), $script); $this->registerAssets(); }
public function run() { list($this->name, $this->id) = $this->resolveNameId(); if (isset($this->htmlOptions['placeholder'])) { $this->options['placeholder'] = $this->htmlOptions['placeholder']; } $data = array(); if (isset($this->options['placeholder'])) { $data[''] = ''; } $this->data = $data + $this->data; if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } else { $this->htmlOptions['id'] = $this->id; echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions); } $bu = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/'); $cs = Yii::app()->clientScript; $cs->registerCssFile($bu . '/select2.css'); if ($this->scriptPosition === null) { $this->scriptPosition = $cs->coreScriptPosition; } $cs->registerScriptFile($bu . '/select2.js', $this->scriptPosition); $options = $this->options ? CJavaScript::encode($this->options) : ''; $cs->registerScript(__CLASS__ . '#' . $this->id, "\$('#{$this->id}').select2({$options});"); }
public function run() { list($name, $id) = $this->resolveNameID(); if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $this->htmlOptions['id'] = $id; } if (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } else { $this->htmlOptions['name'] = $name; } $l = Language::loadConfig(); $data = array(); foreach ($l['languages'] as $k => $v) { $data[$k] = Yii::t('languages', $v); } if ($this->empty) { $data = array_merge(array('' => Yii::t('cms', $this->empty)), $data); } if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $data, $this->htmlOptions); } else { echo CHtml::dropDownList($name, $this->value, $data, $this->htmlOptions); } }
/** * Renders the filter cell content. Here we can provide HTML options for actual filter input */ protected function renderFilterCellContent() { if (is_string($this->filter)) { echo $this->filter; } else { if ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) { if ($this->filterInputOptions) { $filterInputOptions = $this->filterInputOptions; if (empty($filterInputOptions['id'])) { $filterInputOptions['id'] = false; } } else { $filterInputOptions = array(); } if (is_array($this->filter)) { $filterInputOptions['prompt'] = ''; echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, $filterInputOptions); } else { if ($this->filter === null) { echo CHtml::activeTextField($this->grid->filter, $this->name, $filterInputOptions); } } } else { parent::renderFilterCellContent(); } } }
/** * Run this widget. * This method registers necessary javascript and renders the needed HTML code. */ public function run() { list($name, $id) = $this->resolveDropDownNameID(); // Render drop-down element and hide it with javascript if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->dropDownAttribute, $this->data, $this->dropDownHtmlOptions); } else { echo CHtml::dropDownList($name, $this->value, $this->data, $this->dropDownHtmlOptions); } // Put the script to hide the select-element directly after the element itself, so it is hidden directly after it is rendered // Resource: http://www.electrictoolbox.com/jquery-hide-text-page-load-show-later/ // Note: You can also hide the select-element by adding the css-style 'display:none' to the dropDownHtmlOptions. // We prefer the following JS-Code because of backward compatibility: if the user has JS disabled, // multiselect will not work, but the original select-element will stay visible. echo '<script type="text/javascript"> $("#' . $id . '").hide(); </script>'; $joptions = CJavaScript::encode($this->options); $jfilterOptions = CJavaScript::encode($this->filterOptions); if ($this->options['filter'] === true) { $jscode = "jQuery('#{$id}').multiselect({$joptions}).multiselectfilter({$jfilterOptions});"; unset($this->options['filter']); } else { $jscode = "jQuery('#{$id}').multiselect({$joptions});"; } // start - by jeremy@Yii if ($this->options['ajaxRefresh'] == true) { $jscode .= "jQuery('body').ajaxComplete(function() {jQuery('#" . $id . "').multiselect(" . $joptions . "); });"; } // end - by jeremy@Yii Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $jscode); }
/** * Renders the select2 field */ public function renderField() { if ($this->hasModel()) { echo $this->asDropDownList ? \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->options) : \CHtml::activeHiddenField($this->model, $this->attribute); } else { echo $this->asDropDownList ? \CHtml::dropDownList($this->options['name'], $this->value, $this->data, $this->options) : \CHtml::hiddenField($this->options['name'], $this->value); } }
/** * Renders the multiselect field */ public function renderField() { if ($this->hasModel()) { echo \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->options); } else { echo \CHtml::dropDownList($this->name, $this->value, $this->data, $this->options); } }
public function run() { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->input_element->items, array( 'multiple' => 'multiple', 'key' => isset($this->key) ? $this->key : 'id', 'class' => 'multiselect' )); }
/** * @param $model - profile model * @param $field - profile fields model item * @param $params - htmlOptions * @return string */ public function editAttribute($model,$field,$htmlOptions=array()) { $list = array(); if ($this->params['emptyField']) $list[0] = $this->params['emptyField']; $models = CActiveRecord::model($this->params['modelName'])->findAll(); foreach ($models as $m) $list[$m->id] = (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id); return CHtml::activeDropDownList($model,$field->varname,$list,$htmlOptions=array()); }
public function renderField() { list($name, $id) = $this->resolveNameID(); if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } else { echo CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions); } }
public function run() { if ($this->selector == null) { list($this->name, $this->id) = $this->resolveNameId(); $this->selector = '#' . $this->id; if (isset($this->htmlOptions['placeholder'])) { $this->options['placeholder'] = $this->htmlOptions['placeholder']; } if (!isset($this->htmlOptions['multiple'])) { $data = array(); if (isset($this->options['placeholder'])) { $data[''] = ''; } $this->data = $data + $this->data; } if ($this->hasModel()) { if (isset($this->options['ajax'])) { echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions); } else { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } } elseif (!isset($this->options['ajax'])) { $this->htmlOptions['id'] = $this->id; echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions); } else { echo CHtml::hiddenField($this->name, $this->value, $this->htmlOptions); } } $bu = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/'); $cs = Yii::app()->clientScript; //$cs->registerCssFile($bu . '/select2.css'); if (YII_DEBUG) { $cs->registerScriptFile($bu . '/select2.js'); } else { $cs->registerScriptFile($bu . '/select2.min.js'); } if ($this->sortable) { $cs->registerCoreScript('jquery.ui'); } $options = CJavaScript::encode(CMap::mergeArray($this->defaultOptions, $this->options)); ob_start(); echo "jQuery('{$this->selector}').select2({$options})"; foreach ($this->events as $event => $handler) { echo ".on('{$event}', " . CJavaScript::encode($handler) . ")"; } echo ';'; if ($this->sortable) { echo <<<JavaScript jQuery('{$this->selector}').select2("container").find("ul.select2-choices").sortable({ \tcontainment: 'parent', \tstart: function() { jQuery('{$this->selector}').select2("onSortStart"); }, \tupdate: function() { jQuery('{$this->selector}').select2("onSortEnd"); } }); JavaScript; } $cs->registerScript(__CLASS__ . '#' . $this->id, ob_get_clean()); }
public function renderField() { $this->htmlOptions['multiple'] = 'multiple'; if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } else { echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions); } }
public static function enumDropDownList($model, $attribute, $htmlOptions = array(), $default = NULL) { $enumValues = self::enumItem($model, $attribute); if (!empty($default)) { // This will return a <option value="defaul"></option> $enumValues = array($default['value'] => (string) $default['label']) + $enumValues; } // echo var_export($enumValues, TRUE); return CHtml::activeDropDownList($model, $attribute, $enumValues, $htmlOptions); }
public function run() { $type = DataType::getInputType($this->column->dbType); $this->htmlOptions += $this->fixedHtmlOptions[$type]; $column = $this->column->name; $name = isset($this->htmlOptions['name']) ? $this->htmlOptions['name'] : 'Row[' . $column . ']'; switch ($type) { case 'number': echo CHtml::activeTextField($this->row, $column, $this->htmlOptions); break; case 'select': echo CHtml::activeDropDownList($this->row, $column, $this->getEnumValues(), $this->htmlOptions); break; case 'select-multiple': #echo CHtml::activeListBox($this->row, $column, $this->getSetValues(), $this->htmlOptions); echo CHtml::listBox($name, $this->row->getAttributeAsArray($column), $this->getSetValues(), $this->htmlOptions); break; case 'text': echo CHtml::activeTextArea($this->row, $column, $this->htmlOptions); break; case 'file': echo '<script type="text/javascript"> $(document).ready(function() { $("# echo CHtml::$idPrefix; ?>").submit(function() { alert("ok1"); }); }); </script>'; echo CHtml::activeFileField($this->row, $column, $this->htmlOptions); break; case 'date': $this->SetDateTimeHtmlOptions($column); echo CHtml::activeTextField($this->row, $column, $this->htmlOptions); echo '<script type="text/javascript"> $(document).ready(function() { $("#' . $this->htmlOptions['id'] . '").datepicker({showOn: "button", dateFormat: "yy-mm-dd", buttonImage: "' . ICONPATH . '/16/calendar.png' . '", buttonImageOnly: true, buttonText: "' . Yii::t('core', 'showCalendar') . '"}); }); </script>'; break; case 'datetime': $this->SetDateTimeHtmlOptions($column); echo CHtml::activeTextField($this->row, $column, $this->htmlOptions); echo '<script type="text/javascript"> $(document).ready(function() { now = new Date(); $("#' . $this->htmlOptions['id'] . '").datepicker({showOn: "button", dateFormat: "yy-mm-dd " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds(), buttonImage: "' . ICONPATH . '/16/calendar.png' . '", buttonImageOnly: true, buttonText: "' . Yii::t('core', 'showCalendar') . '"}); }); </script>'; break; default: echo CHtml::activeTextField($this->row, $column, $this->htmlOptions); break; } }
/** * Renders the select2 field */ public function renderField() { list($name, $id) = $this->resolveNameID(); TbArray::defaultValue('id', $id, $this->htmlOptions); TbArray::defaultValue('name', $name, $this->htmlOptions); if ($this->hasModel()) { echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute); } else { echo $this->asDropDownList ? CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($this->name, $this->value); } }
/** * Renders the filter cell content. */ protected function renderFilterCellContent() { $options = array(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->authManager; /* @var $authItems CAuthItem[] */ $authItems = $am->getAuthItems(); foreach ($authItems as $itemName => $item) { $options[Yii::app()->controller->capitalize(Yii::app()->controller->getItemTypeText($item->type, true))][$itemName] = $item->description; } echo CHtml::activeDropDownList($this->grid->filter, 'authItem', $options, ['prompt' => '']); }
public function getField($widgetId, $rowGroupName = '', $rowIndex, $model, $attribute, $name, $value = '', $fieldClassName = '', $htmlOptions = array(), $hasError = false, $data = '', $params = '') { if ($hasError) { $fieldClassName = $fieldClassName . ' ' . CHtml::$errorCss; } $htmlOptions = ClonnableFields::addClass($htmlOptions, $fieldClassName); if (ClonnableFields::isModel($model)) { return CHtml::activeDropDownList($model, $attribute, $data, $htmlOptions); } else { return CHtml::dropDownList($name, $value, $data, $htmlOptions); } }
public function renderInput($attr) { switch ($attr) { case 'password': echo X2Html::x2ActivePasswordField($this, $attr, $this->htmlOptions($attr), true); break; case 'server': echo CHtml::activeDropDownList($this, 'server', $this->sesEndpoints, $this->htmlOptions($attr)); break; default: parent::renderInput($attr); } }
/** * Renders the multiselect field */ public function renderField() { list($name, $id) = $this->resolveNameID(); TbArray::defaultValue('id', $id, $this->htmlOptions); TbArray::defaultValue('name', $name, $this->htmlOptions); // fixes #32: 'multiple' will be forced later in jQuery plugin $this->htmlOptions['multiple'] = 'multiple'; if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); } else { echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions); } }
/** * @param $model - profile model * @param $field - profile fields model item * @param $params - htmlOptions * @return string */ public function editAttribute($model, $field, $htmlOptions = array()) { $list = array(); if ($this->params['emptyField']) { $list[0] = $this->params['emptyField']; } $models = CActiveRecord::model($this->params['modelName'])->findAll(); foreach ($models as $m) { $attr = $this->params['optionName'] ? $this->params['optionName'] : 'id'; $list[$m->{$attr}] = $m->getAttribute($this->params['relationName']); } return CHtml::activeDropDownList($model, $field->varname, $list, $htmlOptions = array()); }
public function getFilterCellContent() { if (is_string($this->filter)) { return $this->filter; } elseif ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) { if (is_array($this->filter)) { return CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id' => false, 'prompt' => '', 'class' => 'form-control')); } elseif ($this->filter === null) { return CHtml::activeTextField($this->grid->filter, $this->name, array('id' => false, 'class' => 'form-control')); } } else { return parent::getFilterCellContent(); } }
/** * Runs the widget. */ public function run() { list($name, $id) = $this->resolveNameID(); if ($this->hasModel()) { if ($this->form) { echo $this->asDropDownList ? $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : $this->form->hiddenField($this->model, $this->attribute); } else { echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute); } } else { echo $this->asDropDownList ? CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($name, $this->value); } $this->registerClientScript($id); }
public function run() { if (!isset($this->htmlOptions['id'])) { $this->htmlOptions['id'] = $this->id; } if (!isset($this->htmlOptions['empty'])) { $this->htmlOptions['empty'] = $this->empty; } if ($this->model) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->options, $this->htmlOptions); } else { echo CHtml::dropDownList($this->name, $this->current, $this->input_element->items, $this->input_element->attributes); } }
/** * Renders the filter cell content. * This method will render the {@link filter} as is if it is a string. * If {@link filter} is an array, it is assumed to be a list of options, and a dropdown selector will be rendered. * Otherwise if {@link filter} is not false, a text field is rendered. * @since 1.1.1 */ protected function renderFilterCellContent() { if (is_string($this->filter)) { echo $this->filter; } elseif ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) { if (is_array($this->filter)) { echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id' => false, 'prompt' => '')); } elseif ($this->filter === null) { echo CHtml::activeTextField($this->grid->filter, $this->name, array('id' => false)); } } else { parent::renderFilterCellContent(); } }
/** * Renders the filter cell content. * This method will render the {@link filter} as is if it is a string. * If {@link filter} is an array, it is assumed to be a list of options, and a dropdown selector will be rendered. * Otherwise if {@link filter} is not false, a text field is rendered. * @since 1.1.1 */ protected function renderFilterCellContent() { if (is_string($this->filter)) { echo $this->filter; } elseif ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) { if (is_array($this->filter)) { echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id' => false, 'prompt' => '')); } elseif ($this->filter === null) { echo CHtml::activeTextField($this->grid->filter, $this->name, array('id' => false)); } } else { $this->filterHtmlOptions['class'] = 'divtd'; echo CHtml::openTag('div', $this->filterHtmlOptions); $this->renderFilterCellContent(); echo "</div>"; } }
/** * @param $model - profile model * @param $field - profile fields model item * @param $params - htmlOptions * @return string */ public function editAttribute($model, $field, $htmlOptions = array()) { $list = array(); if ($this->params['emptyField']) { $list[0] = $this->params['emptyField']; } $models = CActiveRecord::model($this->params['modelName'])->findAll(); foreach ($models as $m) { $list[$m->getAttribute($m->tableSchema->primaryKey)] = $this->params['optionName'] ? $m->getAttribute($this->params['optionName']) : $m->getAttribute($m->tableSchema->primaryKey); } return CHtml::activeDropDownList($model, $field->varname, $list, $htmlOptions = array('ajax' => array('type' => 'POST', 'url' => CController::createUrl('/fm/fields/getDroDownDepValues'), 'data' => array('model' => $this->params['modelDestName'], 'field_dest' => $this->params['destField'], 'varname' => $field->VARNAME, $field->varname => 'js:this.value', 'optionDestName' => $this->params['optionDestName']), 'success' => 'function(data){ $("#ajax_loader").hide(); $("#Profile_' . $this->params['destField'] . '").html(data) }', 'beforeSend' => 'function(){ $("#ajax_loader").fadeIn(); }'))); }
/** * Renders the input file field */ public function renderField() { list($name, $id) = $this->resolveNameID(); TbArray::defaultValue('id', $id, $this->htmlOptions); TbArray::defaultValue('name', $name, $this->htmlOptions); if ($this->useHelperSelectBox) { $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array('class' => 'yiiwheels.widgets.formhelpers.WhSelectBox', 'htmlOptions' => $this->htmlOptions, 'model' => $this->model, 'attribute' => $this->attribute, 'name' => $this->name, 'value' => $this->value, 'wrapperOptions' => array('class' => 'bfh-fonts', 'data-family' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value)))); $select->init(); $select->run(); } else { $this->htmlOptions['data-family'] = $this->hasModel() ? $this->model->{$this->attribute} : $this->value; if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions); } else { echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions); } } }
/** * Renders a dropdown list for the helper */ protected function dropDownList() { if (!$this->useHelperSelectBox) { return $this->hasModel() ? CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions) : CHtml::dropDownList($this->name, $this->value, array(), $this->htmlOptions); } else { ob_start(); ob_implicit_flush(false); try { $widget = Yii::createComponent(array('class' => 'yiiwheels.widgets.formhelpers.WhSelectBox', 'model' => $this->model, 'attribute' => $this->attribute, 'name' => $this->name, 'value' => $this->value, 'htmlOptions' => $this->htmlOptions)); $widget->init(); $widget->run(); } catch (Exception $e) { ob_end_clean(); throw $e; } return ob_get_clean(); } }
protected function renderFilterCellContent() { if (is_string($this->filter)) { echo $this->filter; } elseif ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) { if (is_array($this->filter)) { echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id' => false, 'prompt' => '')); } elseif ($this->filter === null) { $hOptions = array('id' => false, 'accesskey' => $this->accesskey); if ($this->autoFocus) { $hOptions = array_merge($hOptions, array('autofocus' => 'autofocus')); } echo CHtml::activeTextField($this->grid->filter, $this->name, $hOptions); // 'placeholder' => '[Alt]+['.$this->accesskey.']')); } } else { parent::renderFilterCellContent(); } }
/** * Run this widget. * This method renders the needed HTML code. */ public function run() { list($name, $id) = $this->resolveNameID(); if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $this->htmlOptions['id'] = $id; } if (isset($this->htmlOptions['name'])) { $name = $this->htmlOptions['name']; } if (isset($this->htmlOptions['multiple'])) { unset($this->htmlOptions['multiple']); } if ($this->hasModel()) { echo CHtml::activeDropDownList($this->model, $this->attribute, $this->value, $this->htmlOptions); } else { echo CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions); } }