How do I make the minDate be the value of another field?
How do I make the
minDate
of date_of_payment
, expected_release
, and date_received
be whatever the value of date_requested
?
Section::make('Request information')
->schema([
Grid::make([
'sm' => 2,
'lg' => 3,
])
->schema([
TextInput::make('receipt_no')
->required(),
TextInput::make('purpose')
->required(),
TextInput::make('registrar_name'),
DatePicker::make('date_requested')
->maxDate(now())
->required(),
DatePicker::make('date_of_payment')
->required(),
DatePicker::make('expected_release')
->required(),
DatePicker::make('date_received'),
]),
]),
Section::make('Request information')
->schema([
Grid::make([
'sm' => 2,
'lg' => 3,
])
->schema([
TextInput::make('receipt_no')
->required(),
TextInput::make('purpose')
->required(),
TextInput::make('registrar_name'),
DatePicker::make('date_requested')
->maxDate(now())
->required(),
DatePicker::make('date_of_payment')
->required(),
DatePicker::make('expected_release')
->required(),
DatePicker::make('date_received'),
]),
]),
2 Replies
Solution
Thanks! This worked for me:
DatePicker::make('date_requested')
->maxDate(now())
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('date_of_payment', $state);
$set('expected_release', $state);
$set('date_received', $state);
}),
DatePicker::make('date_of_payment')
->minDate(fn (callable $get) => $get('date_requested'))
->required(),
DatePicker::make('expected_release')
->minDate(fn (callable $get) => $get('date_requested'))
->required(),
DatePicker::make('date_received')
->minDate(fn (callable $get) => $get('date_requested')),
DatePicker::make('date_requested')
->maxDate(now())
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('date_of_payment', $state);
$set('expected_release', $state);
$set('date_received', $state);
}),
DatePicker::make('date_of_payment')
->minDate(fn (callable $get) => $get('date_requested'))
->required(),
DatePicker::make('expected_release')
->minDate(fn (callable $get) => $get('date_requested'))
->required(),
DatePicker::make('date_received')
->minDate(fn (callable $get) => $get('date_requested')),