1 | <?php |
||
37 | class InputWidget extends Widget |
||
38 | { |
||
39 | /** |
||
40 | * @var \yii\widgets\ActiveField active input field, which triggers this widget rendering. |
||
41 | * This field will be automatically filled up in case widget instance is created via [[\yii\widgets\ActiveField::widget()]]. |
||
42 | * @since 2.0.11 |
||
43 | */ |
||
44 | public $field; |
||
45 | /** |
||
46 | * @var Model the data model that this widget is associated with. |
||
47 | */ |
||
48 | public $model; |
||
49 | /** |
||
50 | * @var string the model attribute that this widget is associated with. |
||
51 | */ |
||
52 | public $attribute; |
||
53 | /** |
||
54 | * @var string the input name. This must be set if [[model]] and [[attribute]] are not set. |
||
55 | */ |
||
56 | public $name; |
||
57 | /** |
||
58 | * @var string the input value. |
||
59 | */ |
||
60 | public $value; |
||
61 | /** |
||
62 | * @var array the HTML attributes for the input tag. |
||
63 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
64 | */ |
||
65 | public $options = []; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Initializes the widget. |
||
70 | * If you override this method, make sure you call the parent implementation first. |
||
71 | */ |
||
72 | 1 | public function init() |
|
73 | { |
||
74 | 1 | if ($this->name === null && !$this->hasModel()) { |
|
75 | throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified."); |
||
76 | } |
||
77 | 1 | if (!isset($this->options['id'])) { |
|
78 | 1 | $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId(); |
|
79 | } |
||
80 | 1 | parent::init(); |
|
81 | 1 | } |
|
82 | |||
83 | /** |
||
84 | * @return bool whether this widget is associated with a data model. |
||
85 | */ |
||
86 | 1 | protected function hasModel() |
|
90 | |||
91 | /** |
||
92 | * Render a HTML input tag. |
||
93 | * |
||
94 | * This will call [[Html::activeInput()]] if the input widget is [[hasModel()|tied to a model]], |
||
95 | * or [[Html::input()]] if not. |
||
96 | * |
||
97 | * @param string $type the type of the input to create. |
||
98 | * @return string the HTML of the input field. |
||
99 | * @since 2.0.13 |
||
100 | * @see Html::activeInput() |
||
101 | * @see Html::input() |
||
102 | */ |
||
103 | protected function renderInputHtml($type) |
||
110 | } |
||
111 |