64robots / nova-fields

A collection of customizable Nova Fields.
https://nova-fields.netlify.com
MIT License
286 stars 78 forks source link

Image uploads in JSON field? #86

Open PaulLawton227 opened 5 years ago

PaulLawton227 commented 5 years ago

Lovin' your work on this JSON field. Do you have any plans to make Image uploads inside the JSON field (ideally your NovaImageCropper)?

beliolfa commented 5 years ago

Hey! Sorry about the delay.

Can you provide a real world example of sending an image inside a JSON field? Currently we are sending a strinigify json to the server and this is not possible. But maybe we could think a way to achive this feature.

Thanks!

PaulLawton227 commented 5 years ago

We have an instructor with basic name, handle, email and a metafield for storing all the extra data that defines an instructor.

e.g.

JSON::make( __('Metafields'), [
                Text::make(__('Title'), 'title'),
                Text::make(__('Previous Job Title'), 'previous_job_title'),
                Text::make(__('Instagram Handle'), 'instagram_handle'),
                Textarea::make(__('Quote'), 'quote'),
                Repeater::make(__('Key stats'), 'key_stats')
                    ->addField([
                        'label' => 'Stat.',
                        'name' => 'stat',
                        'type' => 'text',
                    ]),
            ], 'metafields'),

inside this json field - we would want to add a photo field e.g.

            ImageCropper::make('photo')
                ->aspectRatio(1)
                ->maxWidth(800),

and any number of 'additional' images e.g. image_1, image_2. We'd like these images to go in the metafields - so that we don't have to keep adding extra image fields into the database migrations when the client says "can we have another image?"

beliolfa commented 5 years ago

hmm so im thinking on adding a new method like ->sendAsArray() or similar that allow us to send Files in the formData. The default behavior in JSON field is flat all the fields in a JSON stringified string.

I'll think about it. PRs welcome!