Skip to content

Commit

Permalink
Update dependencies and fix DateTimePicker widget. (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Jan 2, 2024
1 parent b5c37c4 commit ed47673
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.6",
"php-forge/support": "dev-main",
"phpunit/phpunit": "^10.2",
"roave/infection-static-analysis-plugin": "^1.32",
"phpunit/phpunit": "10.5.3",
"roave/infection-static-analysis-plugin": "^1.34",
"yii2-extensions/phpstan": "dev-main"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
]
},
"logs": {
"text": "php:\/\/stderr",
"text": "infection.log",
"stryker": {
"report": "main"
}
Expand Down
8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
includes:
- vendor/yii2-extensions/phpstan/extension.neon

parameters:
bootstrapFiles:
- tests/Support/bootstrap.php

dynamicConstantNames:
- YII_DEBUG
- YII_ENV
- YII_ENV_DEV
- YII_ENV_PROD
- YII_ENV_TEST

level: 2

Expand Down
21 changes: 14 additions & 7 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;
use PHPForge\Html\Input\Text;
use PHPForge\Html\Label;
use PHPForge\Html\Span;
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,10 +144,7 @@ private function renderDateTimePicker(): string
->dataAttributes(['td-target' => "#$this->id", 'td-toggle' => 'datetimepicker'])
->class($this->spanClass)
->content($this->icon);
$input = Input::widget()
->attributes($this->options)
->dataAttributes(['td-target' => "#$this->id"])
->type('text');
$input = Text::widget()->attributes($this->options)->dataAttributes(['td-target' => "#$this->id"]);

$input = match ($this->hasModel()) {
true => $input
Expand Down Expand Up @@ -172,6 +176,9 @@ private function renderDateTimePicker(): string
};
}

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

0 comments on commit ed47673

Please sign in to comment.