TbHtml::activeDropDownList PHP Method

activeDropDownList() public static method

Generates a drop down list for a model attribute.
public static activeDropDownList ( CModel $model, string $attribute, array $data, array $htmlOptions = [] ) : string
$model CModel the data model.
$attribute string the attribute.
$data array data for generating the list options (value=>display).
$htmlOptions array additional HTML attributes
return string the generated drop down list.
    public static function activeDropDownList($model, $attribute, $data, $htmlOptions = array())
    {
        $displaySize = TbArray::popValue('displaySize', $htmlOptions);
        // In case we do need to create a div container for the input element (i.e. has addon or defined col)
        $containerOptions = array();
        // Get the intended input width before the rest of the options are normalized
        self::addSpanClass($htmlOptions);
        self::addColClass($htmlOptions);
        $col = self::popColClasses($htmlOptions);
        $htmlOptions = self::normalizeInputOptions($htmlOptions);
        self::addCssClass('form-control', $htmlOptions);
        if (!empty($displaySize)) {
            $htmlOptions['size'] = $displaySize;
        }
        if (!empty($col)) {
            self::addCssClass($col, $containerOptions);
        }
        $output = '';
        if (!empty($containerOptions)) {
            $output .= self::openTag('div', $containerOptions);
        }
        $output .= parent::activeDropDownList($model, $attribute, $data, $htmlOptions);
        if (!empty($containerOptions)) {
            $output .= '</div>';
        }
        return $output;
    }

Usage Example

Example #1
0
 /**
  * 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 TbHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, $filterInputOptions);
             } else {
                 if ($this->filter === null) {
                     echo TbHtml::activeTextField($this->grid->filter, $this->name, $filterInputOptions);
                 }
             }
         } else {
             parent::renderFilterCellContent();
         }
     }
 }
All Usage Examples Of TbHtml::activeDropDownList
TbHtml