invaders-xx / filament-jsoneditor

MIT License
22 stars 14 forks source link

'json' and 'array' cast columns are escaped when they shouldn't be #29

Closed idealerror closed 9 months ago

idealerror commented 9 months ago

I'm trying to update an existing 'array' column that originally shows as

[ 
    "email"
]

When I save it, the column gets stored as:

"[\n  \"email\"\n]"

How do I stop it from sanitizing the column? Is this a filament setting or an issue with this package?

idealerror commented 9 months ago

Nevermind, this is no longer an issue.

tipmisle commented 7 months ago

@idealerror Hey, I have the same problem, what fixed it for you? Thanks

I have set $casts for my field as array, and initially it shows ok but after saving it gets mangled

"{\"title\":

tipmisle commented 7 months ago

nevermind: I fixed it with: https://github.com/invaders-xx/filament-jsoneditor/issues/27#issuecomment-1827958924 ->dehydrateStateUsing(function ($state) { if(is_string($state)){ return json_decode($state, true); } return $state; })

Full field:

\InvadersXX\FilamentJsoneditor\Forms\JSONEditor::make('default_settings')
                    ->modes(['code', 'form', 'text', 'tree', 'view', 'preview'])
                    ->dehydrateStateUsing(function ($state) {
                        if(is_string($state)){
                            return json_decode($state, true);
                        }
                        return $state;
                    }),