F
Filament12mo ago
jaocero

How do I ignore the minDate() validation if its the default value?

This is an infolist action which it has a a form inside. Now in my date picker the behavior is that the minimum date to be selected is the current date but the default value is example the old date like November 6, 2023. I just want to ignore the validation since I don't want to change the date. Can someone help me with this?
Infolists\Components\Actions\Action::make('edit_purpose')
->label('Edit Purpose')
->icon('heroicon-m-pencil-square')
->modalIcon('heroicon-s-pencil-square')
->modalDescription('Edit the purpose of the program.')
->modalSubmitActionLabel('Save Changes')
->form([
Forms\Components\DatePicker::make('desired_pentesting_date')
->label('What is the desired start date for penetration testing?')
->placeholder('Select a Desired Start Date')
->required()
->native(false)
->minDate(now()->startOfDay()) // want to have the minimum date behavior but ignore if the default value is not change
->prefix('Starts')
->suffix('at midnight')
->closeOnDateSelection()
->default(fn ($record) => $record->purpose->desired_start_date_at)
->validationAttribute('desired pentesting date'),
])
->stickyModalHeader()
->stickyModalFooter()
->action(function (array $data) {
dd($data);
});
Infolists\Components\Actions\Action::make('edit_purpose')
->label('Edit Purpose')
->icon('heroicon-m-pencil-square')
->modalIcon('heroicon-s-pencil-square')
->modalDescription('Edit the purpose of the program.')
->modalSubmitActionLabel('Save Changes')
->form([
Forms\Components\DatePicker::make('desired_pentesting_date')
->label('What is the desired start date for penetration testing?')
->placeholder('Select a Desired Start Date')
->required()
->native(false)
->minDate(now()->startOfDay()) // want to have the minimum date behavior but ignore if the default value is not change
->prefix('Starts')
->suffix('at midnight')
->closeOnDateSelection()
->default(fn ($record) => $record->purpose->desired_start_date_at)
->validationAttribute('desired pentesting date'),
])
->stickyModalHeader()
->stickyModalFooter()
->action(function (array $data) {
dd($data);
});
No description
Solution:
I've got it working: in the datepicker minDate() function it has rule: ```php public function minDate(CarbonInterface | string | Closure | null $date): static {...
Jump to solution
2 Replies
jaocero
jaoceroOP12mo ago
No description
Solution
jaocero
jaocero12mo ago
I've got it working: in the datepicker minDate() function it has rule:
public function minDate(CarbonInterface | string | Closure | null $date): static
{
$this->minDate = $date;

$this->rule(static function (DateTimePicker $component) {
return "after_or_equal:{$component->getMinDate()}";
}, static fn (DateTimePicker $component): bool => (bool) $component->getMinDate());

return $this;
}
public function minDate(CarbonInterface | string | Closure | null $date): static
{
$this->minDate = $date;

$this->rule(static function (DateTimePicker $component) {
return "after_or_equal:{$component->getMinDate()}";
}, static fn (DateTimePicker $component): bool => (bool) $component->getMinDate());

return $this;
}
now idk if this is the bestway or correct way but I've got it working by creating macro:
DatePicker::macro('minDateWithoutRule', function (CarbonInterface | string | Closure | null $date) {
$this->minDate = $date;
return $this;
});
DatePicker::macro('minDateWithoutRule', function (CarbonInterface | string | Closure | null $date) {
$this->minDate = $date;
return $this;
});
then use it like this: ->minDateWithoutRule(now()->startOfDay()),
Want results from more Discord servers?
Add your server