Same field entered in varying formats
Is it possible for me to enter a field as a string or as a date, depending upon another field.
I have tried the following which shows the correct input, however, if the TextInput is shown, the contents are blank:
TextInput::make('value')->visible(function($record) {return ($record->type!=='date');}),
DatePicker::make('value')->visible(function($record) {return ($record->type==='date');}),
2 Replies
I have come up with a solution - not sure if there is a better way but this works:
$schema = [
TextInput::make('code')
->disabled(),
Select::make('type')
->options([
'date' => 'Date',
'string' => 'String',
'integer' => 'Number',
'decimal' => 'Decimal',
'binary' => 'On/Off'
]),
TextInput::make('name')->disabled(),
];
if ($form->model->type==='date') {
$schema2 = [DatePicker::make('value'),];
} else {
$schema2 = [TextInput::make('value'),];
}
$schema = array_merge($schema,$schema2);
return $form->schema($schema);
So if i read your code correct you have a column in your database that can be text or a date?