Skip to content

Commit b77e32f

Browse files
committed
- Added option to pass a custom date format to dates and datetime inputs
Signed-off-by: Arushad Ahmed <dash-8x@hotmail.com>
1 parent 5b47f11 commit b77e32f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Views/Components/Date.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Javaabu\Forms\Views\Components;
44

5+
use DateTimeInterface;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Carbon;
8+
59
class Date extends Input
610
{
711
public string $icon;
@@ -20,6 +24,7 @@ public function __construct(
2024
string $type = 'date',
2125
$model = null,
2226
$default = null,
27+
public string $dateFormat = '',
2328
string $icon = '',
2429
string $clearIcon = '',
2530
string $clearBtnClass = '',
@@ -70,4 +75,13 @@ public function isDateInput(): bool
7075
{
7176
return true;
7277
}
78+
79+
protected function formatDateTime(Model $model, string $key, DateTimeInterface $date)
80+
{
81+
if (! $this->dateFormat) {
82+
return parent::formatDateTime($model, $key, $date);
83+
}
84+
85+
return $date->format($this->dateFormat);
86+
}
7387
}

src/Views/Components/Datetime.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function __construct(
1414
string $label = '',
1515
$model = null,
1616
$default = null,
17+
string $dateFormat = '',
1718
string $icon = '',
1819
string $clearIcon = '',
1920
string $clearBtnClass = '',
@@ -36,6 +37,7 @@ public function __construct(
3637
type: 'datetime',
3738
model: $model,
3839
default: $default,
40+
dateFormat: $dateFormat,
3941
icon: $icon,
4042
clearIcon: $clearIcon,
4143
clearBtnClass: $clearBtnClass,

0 commit comments

Comments
 (0)