From a6d28da00b5652beb2ebe674e2943cb60895755d Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 2 Jan 2024 13:33:09 -0300 Subject: [PATCH] Refactor DateTimePicker class to use Text widget instead of Tag widget. --- src/DateTimePicker.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/DateTimePicker.php b/src/DateTimePicker.php index dc8c94b..15a4e42 100644 --- a/src/DateTimePicker.php +++ b/src/DateTimePicker.php @@ -4,12 +4,14 @@ namespace Yii2\Extensions\DateTimePicker; +use JsonException; use PHPForge\Html\Div; use PHPForge\Html\Helper\CssClass; +use PHPForge\Html\Input\Text; use PHPForge\Html\Label; use PHPForge\Html\Span; -use PHPForge\Html\Tag; use Yii; +use yii\base\InvalidConfigException; use yii\helpers\Html; use yii\widgets\InputWidget; @@ -33,6 +35,9 @@ final class DateTimePicker extends InputWidget public int $startOfTheWeek = 1; public string $template = "{label}\n{input}\n{span}"; + /** + * @throws InvalidConfigException + */ public function init(): void { parent::init(); @@ -88,9 +93,12 @@ public function run(): string return $this->renderDateTimePicker(); } + /** + * @throws JsonException + */ private function getScript(): string { - $config = json_encode($this->config); + $config = json_encode($this->config, JSON_THROW_ON_ERROR); return <<floatingLabel ? "{input}\n{span}\n{label}" : "{input}\n{span}"; CssClass::add($containerOptions, $this->floatingLabel ? 'form-floating' : ''); @@ -137,11 +144,7 @@ private function renderDateTimePicker(): string ->dataAttributes(['td-target' => "#$this->id", 'td-toggle' => 'datetimepicker']) ->class($this->spanClass) ->content($this->icon); - $input = Tag::widget() - ->attributes($this->options) - ->dataAttributes(['td-target' => "#$this->id"]) - ->tagName('input') - ->type('text'); + $input = Text::widget()->attributes($this->options)->dataAttributes(['td-target' => "#$this->id"]); $input = match ($this->hasModel()) { true => $input @@ -173,6 +176,9 @@ private function renderDateTimePicker(): string }; } + /** + * @throws JsonException + */ private function registerClientScript(): void { $view = $this->getView();