Bug: Json Editor outputs nothing when json field is casted as array in model class
ziming opened this issue · 9 comments
Hi @invaders-xx ,
Thanks for creating this wonderful package, however it display nothing when the json field is casted as an array or object in the model class
Thank you.
Thanks for the PR
@invaders-xx could you re-open this issue? Thanks!
@ziming, reopened ;-)
If anyone else is having this difficulty, here is a work-around...put this in your Edit class for the resource:
protected function mutateFormDataBeforeFill(array $data): array
{
$data['attributes'] = json_encode($data['attributes']);
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
$data['attributes'] = json_decode($data['attributes']);
return $data;
}
(obviously swapping out the "attributes" with your field name...I'm using this a a stop-gap way to edit Spatie SchemalessAttributes)
There is a pending PR. Should be merged today
This is not working for me - I have a cast on my column called "layout". This is the data in the database:
[{"name": "Grid 1", "type": "grid", "fields": ["invoice_number", "invoice_date"], "columns": 2}, {"name": "Grid 2", "type": "grid", "fields": ["vendor_name", "vendor_address"], "columns": 2}, {"name": "Grid 3", "type": "grid", "fields": ["due_date", "currency"], "columns": 2}, {"name": "Invoice Lines", "type": "array", "fields": [{"key": "invoice_lines.description", "name": "Description", "type": "text"}, {"key": "invoice_lines.quantity", "name": "Quantity", "type": "number"}, {"key": "invoice_lines.unit_price", "name": "Unit Price", "type": "currency"}, {"key": "invoice_lines.total_price", "name": "Total Price", "type": "currency"}, {"key": "invoice_lines.total_price2", "name": "Total Price 2", "type": "currency"}]}, {"name": "Grid 4", "type": "grid", "fields": ["subtotal", "tax", "total"], "columns": 3}]
I get this error in Filament with the plugin:
caught SyntaxError: Unexpected token 'o', "[object Obj"... is not valid JSON
I have more or less the same issue, except that I don't get an exception, but the field is empty
This is still an issue, why it's close?
@invaders-xx your package is impressive and I see you still maintaining it, please let's fix this issue, it has been since 2022