yii\widgets\ActiveField::widget PHP Method

widget() public method

Note that the widget must have both model and attribute properties. They will be initialized with [[model]] and [[attribute]] of this field, respectively. If you want to use a widget that does not have model and attribute properties, please use ActiveField::render instead. For example to use the MaskedInput widget to get some date input, you can use the following code, assuming that $form is your ActiveForm instance: php $form->field($model, 'date')->widget(\yii\widgets\MaskedInput::className(), [ 'mask' => '99/99/9999', ]); If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.
public widget ( string $class, array $config = [] )
$class string the widget class name.
$config array name-value pairs that will be used to initialize the widget.
    public function widget($class, $config = [])
    {
        /* @var $class \yii\base\Widget */
        $config['model'] = $this->model;
        $config['attribute'] = $this->attribute;
        $config['view'] = $this->form->getView();
        if (isset($config['options']) && isset(class_parents($class)['yii\\widgets\\InputWidget'])) {
            $this->adjustLabelFor($config['options']);
        }
        $this->parts['{input}'] = $class::widget($config);
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 public function widget($class, $config = [])
 {
     $config = array_merge(['options' => $this->inputOptions], $config);
     return parent::widget($class, $config);
 }
All Usage Examples Of yii\widgets\ActiveField::widget