From 67adcf30b99b3b1b24d04ca3995a93f0e4c217d8 Mon Sep 17 00:00:00 2001 From: Martin Brettschneider Date: Fri, 17 Nov 2023 20:13:30 +0100 Subject: [PATCH] feat: switch to native date inputs --- .docs/filters.md | 11 ----- src/Filter/FilterDate.php | 31 ++---------- src/Filter/FilterDateRange.php | 37 ++------------ src/Filter/IFilterDate.php | 10 ---- src/templates/datagrid_filter_date.latte | 28 ----------- src/templates/datagrid_filter_daterange.latte | 48 ------------------- 6 files changed, 7 insertions(+), 158 deletions(-) delete mode 100644 src/templates/datagrid_filter_date.latte delete mode 100644 src/templates/datagrid_filter_daterange.latte diff --git a/.docs/filters.md b/.docs/filters.md index c14061ff..cfc4ff12 100644 --- a/.docs/filters.md +++ b/.docs/filters.md @@ -189,17 +189,6 @@ Keep in mind that `FilterMultiSelect` uses `bootstrap-select` JS library. Read m $grid->addFilterDate('created', 'User registerd on'); ``` -This filter also has some special features. First, it shows datepicker. Second, You can set date format. Sadly, JavaScript has different date formatting modifiers, so you have to set them both at once: - -```php -/** - * This is default formatting - * $php_format, $js_format - */ -$grid->addFilterDate('created', 'User registerd on') - ->setFormat('j. n. Y', 'd. m. yyyy'); -``` - ## FilterRange This filter renders two inputs: From and To. If you want to set inputs placeholders, you have to set both in an array. diff --git a/src/Filter/FilterDate.php b/src/Filter/FilterDate.php index ad5cf803..0f28dc94 100644 --- a/src/Filter/FilterDate.php +++ b/src/Filter/FilterDate.php @@ -7,10 +7,7 @@ class FilterDate extends OneColumnFilter implements IFilterDate { - protected ?string $template = 'datagrid_filter_date.latte'; - - /** @var array */ - protected array $format = ['j. n. Y', 'd. m. yyyy']; + protected ?string $template = 'datagrid_filter_text.latte'; protected ?string $type = 'date'; @@ -18,11 +15,7 @@ public function addToFormContainer(Container $container): void { $control = $container->addText($this->key, $this->name); - $control->setHtmlAttribute('data-provide', 'datepicker') - ->setHtmlAttribute('data-date-orientation', 'bottom') - ->setHtmlAttribute('data-date-format', $this->getJsFormat()) - ->setHtmlAttribute('data-date-today-highlight', 'true') - ->setHtmlAttribute('data-date-autoclose', 'true'); + $control->setHtmlAttribute('type', 'date'); $this->addAttributes($control); @@ -35,30 +28,12 @@ public function addToFormContainer(Container $container): void } } - /** - * Set format for datepicker etc - */ - public function setFormat(string $phpFormat, string $jsFormat): IFilterDate - { - $this->format = [$phpFormat, $jsFormat]; - - return $this; - } - /** * Get php format for datapicker */ public function getPhpFormat(): string { - return $this->format[0]; - } - - /** - * Get js format for datepicker - */ - public function getJsFormat(): string - { - return $this->format[1]; + return 'Y-m-d'; } } diff --git a/src/Filter/FilterDateRange.php b/src/Filter/FilterDateRange.php index 1e427431..38b4f471 100644 --- a/src/Filter/FilterDateRange.php +++ b/src/Filter/FilterDateRange.php @@ -7,10 +7,7 @@ class FilterDateRange extends FilterRange implements IFilterDate { - protected ?string $template = 'datagrid_filter_daterange.latte'; - - /** @var array */ - protected array $format = ['j. n. Y', 'd. m. yyyy']; + protected ?string $template = 'datagrid_filter_range.latte'; protected ?string $type = 'date-range'; @@ -23,19 +20,11 @@ public function addToFormContainer(Container $container): void $from = $container->addText('from', $this->name); - $from->setHtmlAttribute('data-provide', 'datepicker') - ->setHtmlAttribute('data-date-orientation', 'bottom') - ->setHtmlAttribute('data-date-format', $this->getJsFormat()) - ->setHtmlAttribute('data-date-today-highlight', 'true') - ->setHtmlAttribute('data-date-autoclose', 'true'); + $from->setHtmlAttribute('type', 'date'); $to = $container->addText('to', $this->nameSecond); - $to->setHtmlAttribute('data-provide', 'datepicker') - ->setHtmlAttribute('data-date-orientation', 'bottom') - ->setHtmlAttribute('data-date-format', $this->getJsFormat()) - ->setHtmlAttribute('data-date-today-highlight', 'true') - ->setHtmlAttribute('data-date-autoclose', 'true'); + $to->setHtmlAttribute('type', 'date'); $this->addAttributes($from); $this->addAttributes($to); @@ -62,30 +51,12 @@ public function addToFormContainer(Container $container): void } } - /** - * Set format for datepicker etc - */ - public function setFormat(string $phpFormat, string $jsFormat): IFilterDate - { - $this->format = [$phpFormat, $jsFormat]; - - return $this; - } - /** * Get php format for datapicker */ public function getPhpFormat(): string { - return $this->format[0]; - } - - /** - * Get js format for datepicker - */ - public function getJsFormat(): string - { - return $this->format[1]; + return 'Y-m-d'; } } diff --git a/src/Filter/IFilterDate.php b/src/Filter/IFilterDate.php index 2e1534af..809ecb17 100644 --- a/src/Filter/IFilterDate.php +++ b/src/Filter/IFilterDate.php @@ -5,19 +5,9 @@ interface IFilterDate { - /** - * Set format for datepicker etc - */ - public function setFormat(string $phpFormat, string $jsFormat): IFilterDate; - /** * Get php format for datapicker */ public function getPhpFormat(): string; - /** - * Get js format for datepicker - */ - public function getJsFormat(): string; - } diff --git a/src/templates/datagrid_filter_date.latte b/src/templates/datagrid_filter_date.latte deleted file mode 100644 index ad21445b..00000000 --- a/src/templates/datagrid_filter_date.latte +++ /dev/null @@ -1,28 +0,0 @@ -{** - * @param Filter $filter - * @param Nette\Forms\Controls\TextInput $input - * @param string $iconPrefix Icon prefix (fa fa-) - *} - -{if $outer} -
- {label $input class => 'col-sm-3 control-label' /} -
-
- {input $input} - -
-
-
-{else} -
-
- {input $input} - -
-
-{/if} diff --git a/src/templates/datagrid_filter_daterange.latte b/src/templates/datagrid_filter_daterange.latte deleted file mode 100644 index b29fae89..00000000 --- a/src/templates/datagrid_filter_daterange.latte +++ /dev/null @@ -1,48 +0,0 @@ -{** - * @param Filter $filter - * @param Nette\Forms\Container $input - * @param string $iconPrefix Icon prefix (fa fa-) - *} - -{var $container = $input} - -{if $outer} -
- {label $container['from'], class => 'col-sm-3 control-label' /} -
-
- {input $container['from']} - -
-
- {label $container['to'], class => 'filter-range-delimiter col-sm-1 control-label' /} -
-
- {input $container['to']} - -
-
-
-{else} -
-
- {input $container['from']} - -
- -
-
- -
- {input $container['to']} - -
-
-{/if}