/** * @inheritdoc */ public function run() { $hasModel = $this->hasModel(); if ($hasModel) { if (array_key_exists('value', $this->options)) { $value = $this->options['value']; } else { $value = Html::getAttributeValue($this->model, $this->attribute); } } else { $value = $this->value; } if (is_int($value) || is_string($value) && strlen($value) || $value instanceof DateTime || $value instanceof DateTimeInterface) { $formatter = Yii::$app->getFormatter(); try { $altValue = $formatter->asTime($value, $this->altTimeFormat); $value = $formatter->asTime($value, $this->timeFormat); } catch (InvalidParamException $e) { $altValue = $value; } } else { $altValue = $value; } if ($hasModel) { $this->options = array_merge($this->options, ['name' => false, 'value' => $value]); $this->altOptions['value'] = $altValue; $output = Html::activeTextInput($this->model, $this->attribute, $this->options); $output .= Html::activeHiddenInput($this->model, $this->attribute, $this->altOptions); } else { $output = Html::textInput(false, $value, $this->options); $output .= Html::hiddenInput($this->name, $altValue, $this->altOptions); } $js = 'jQuery(\'#' . $this->options['id'] . '\').timepicker(' . Json::htmlEncode($this->clientOptions) . ');'; if (Yii::$app->getRequest()->getIsAjax()) { $output .= Html::script($js); } else { $view = $this->getView(); TimePickerAsset::register($view); TimePickerLanguageAsset::register($view); $view->registerJs($js); } return $output; }