Skip to content

Commit

Permalink
Refactor DateTimePicker class to use Text widget instead of Tag widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 2, 2024
1 parent 7acdc6b commit a6d28da
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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 <<<JS
const htmlElement = document.querySelector('html');
Expand Down Expand Up @@ -124,7 +132,6 @@ private function getScript(): string
private function renderDateTimePicker(): string
{
$containerOptions = [];
$label = '';
$template = $this->floatingLabel ? "{input}\n{span}\n{label}" : "{input}\n{span}";

CssClass::add($containerOptions, $this->floatingLabel ? 'form-floating' : '');
Expand All @@ -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
Expand Down Expand Up @@ -173,6 +176,9 @@ private function renderDateTimePicker(): string
};
}

/**
* @throws JsonException
*/
private function registerClientScript(): void
{
$view = $this->getView();
Expand Down

0 comments on commit a6d28da

Please sign in to comment.