Skip to content

Commit

Permalink
feat: switch to native date inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
martenb committed Nov 17, 2023
1 parent 9a74127 commit 67adcf3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 158 deletions.
11 changes: 0 additions & 11 deletions .docs/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 3 additions & 28 deletions src/Filter/FilterDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,15 @@
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';

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);

Expand All @@ -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';
}

}
37 changes: 4 additions & 33 deletions src/Filter/FilterDateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -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';
}

}
10 changes: 0 additions & 10 deletions src/Filter/IFilterDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
28 changes: 0 additions & 28 deletions src/templates/datagrid_filter_date.latte

This file was deleted.

48 changes: 0 additions & 48 deletions src/templates/datagrid_filter_daterange.latte

This file was deleted.

0 comments on commit 67adcf3

Please sign in to comment.