Validation for custom page

Hello everyone i have a case where when time is filled with value interval start_date and end_date must be filled how i can add validation for this case
Solution:
What about min date? ->minDate(fn($get, $state) => $state)...
Jump to solution
9 Replies
mile4841
mile4841OP4mo ago
the error i am getting for An attempt was made to evaluate a closure for [Filament\Forms\Components\DatePicker], but [$attribute] was unresolvable. for this part of the code

DatePicker::make("start_date")
->label(__("inputs.statistics-start-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->native(false)
->rules([
function($attribute, $value, $fail){
dd($value); // i here get an error fot the $attribute
}
]),

DatePicker::make("start_date")
->label(__("inputs.statistics-start-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->native(false)
->rules([
function($attribute, $value, $fail){
dd($value); // i here get an error fot the $attribute
}
]),
toeknee
toeknee4mo ago
->required() ?
mile4841
mile4841OP4mo ago
yeah but i also need to check is start_date > end_date
Solution
toeknee
toeknee4mo ago
What about min date? ->minDate(fn($get, $state) => $state)
toeknee
toeknee4mo ago
Else use a laravel validation rule
mile4841
mile4841OP4mo ago
thanks bro i will try
toeknee
toeknee4mo ago
make sure to use ->live() on both pickers
mile4841
mile4841OP4mo ago
thanks code that works for me
DatePicker::make("start_date")
->label(__("inputs.statistics-start-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->native(false)
->live()
->required(function(Get $get){
if($get("time") === "interval") return true;
})
->maxDate(function(Get $get, Set $set){
$endDate = $get('end_date');
if ($endDate) {
return Carbon::parse($endDate)->subDay();
}
return now();
})
,
DatePicker::make("end_date")
->label(__("inputs.statistics-end-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->required(function(Get $get){
if($get("time") === "interval") return true;
})
->live()
->minDate(function(Get $get, Set $set){
$startDate = $get('start_date');
if ($startDate) {
return Carbon::parse($startDate)->addDay();
}
return now();
})
->native(false)
DatePicker::make("start_date")
->label(__("inputs.statistics-start-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->native(false)
->live()
->required(function(Get $get){
if($get("time") === "interval") return true;
})
->maxDate(function(Get $get, Set $set){
$endDate = $get('end_date');
if ($endDate) {
return Carbon::parse($endDate)->subDay();
}
return now();
})
,
DatePicker::make("end_date")
->label(__("inputs.statistics-end-date"))
->hidden(function(Get $get){
if($get("time") === "all") return true;
})
->required(function(Get $get){
if($get("time") === "interval") return true;
})
->live()
->minDate(function(Get $get, Set $set){
$startDate = $get('start_date');
if ($startDate) {
return Carbon::parse($startDate)->addDay();
}
return now();
})
->native(false)
Want results from more Discord servers?
Add your server