F
Filamentβ€’7mo ago
Lara Zeus

split json between text field and hint action

this is a sign that I should go to sleep... πŸ™‚ I have a column 'link' cast to array it's look like this
$link = [
'url' => 'https....',
'options' => [
'color'=>'red',
'target'=>'_blank',
//....
],
];
$link = [
'url' => 'https....',
'options' => [
'color'=>'red',
'target'=>'_blank',
//....
],
];
so my Input is:
TextInput::make('link.url')
->live()
->default('https://111')
->hintAction(
Action::make('qr-code-design')
->fillForm(function (Get $get) {
return [
'options' => $get('link.options'),
'url' => $get('link.url'),
];
})
->form([
Grid::make()
->schema([
TextInput::make('url')->default('https://222'),
TextInput::make('options.color')->default('#ccdd33'),
])
])
->action(function (Set $set, $data) {
$set('link', $data);
})
->color('gray')
->icon('heroicon-o-qr-code')
->tooltip('customize the QR code design')
->iconButton()),
TextInput::make('link.url')
->live()
->default('https://111')
->hintAction(
Action::make('qr-code-design')
->fillForm(function (Get $get) {
return [
'options' => $get('link.options'),
'url' => $get('link.url'),
];
})
->form([
Grid::make()
->schema([
TextInput::make('url')->default('https://222'),
TextInput::make('options.color')->default('#ccdd33'),
])
])
->action(function (Set $set, $data) {
$set('link', $data);
})
->color('gray')
->icon('heroicon-o-qr-code')
->tooltip('customize the QR code design')
->iconButton()),
the result after saving to db is {"url":"https:\/\/11111"} the options are never saved to db since they not exist in the main component is there a solution around this?! or better idea
3 Replies
toeknee
toekneeβ€’7mo ago
That's because it's a hint action so theres no way to get the sub data back that I know of anyway... You could try traversal setting a hidden sub fields, but I am not sure you can traverse backwards from a hintAction
Lara Zeus
Lara Zeusβ€’7mo ago
you right didnt want to use hidden fields did managed to make it work with a grid and make everything in nested state still not elegant since it store everything inside nested array will keep an eye on a better way thank you
toeknee
toekneeβ€’7mo ago
Ahh cool stuff!
Want results from more Discord servers?
Add your server
More Posts