invaders-xx / filament-jsoneditor

MIT License
22 stars 14 forks source link

Bug: Json Editor outputs nothing when json field is casted as array in model class #3

Closed ziming closed 2 years ago

ziming commented 2 years ago

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.

invaders-xx commented 2 years ago

Thanks for the PR

ziming commented 2 years ago

@invaders-xx could you re-open this issue? Thanks!

invaders-xx commented 2 years ago

@ziming, reopened ;-)

jwjcmw commented 2 years ago

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)

invaders-xx commented 2 years ago

There is a pending PR. Should be merged today

oliverbj commented 1 year ago

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

rabol commented 1 year ago

I have more or less the same issue, except that I don't get an exception, but the field is empty

mrahmadt commented 1 year ago

This is still an issue, why it's close?

mrahmadt commented 1 year ago

@invaders-xx your package is impressive and I see you still maintaining it, please let's fix this issue, it has been since 2022