invaders-xx / filament-jsoneditor

MIT License
22 stars 15 forks source link

Support json formatted data #10

Closed tanthammar closed 2 years ago

tanthammar commented 2 years ago

This PR allows the field to accept pure JSON data. This is the case if you have a model that casts the field to json.

In FooModel

    protected $casts = [
        'foo_field' => 'json',
    ];

Adds an isJson(bool $state = true) method to the field. Example:

\InvadersXX\FilamentJsoneditor\Forms\JSONEditor::make('foo_field')
        ->isJson()
        ->modes(['tree', 'view'])

This is a non-breaking change as the bool $jsonFormatted property is set to false by default.

TODO It seems like the editor doesn't like other modes than ['tree', 'view'] if it receives json formatted data. Don't know if this is the case for other data formats as well. In my opinion I am fine with this limitation, a note added to the docs would be sufficient to cover the topic.

Ant-V commented 1 year ago

May I suggest to add isJson() in the options area of README.md? Edit: there also seems to be an issue with saving, escaping all characters (even in tree view) Update: The problem with saving happens if there are Unicode characters in any of the fields.