outl1ne / nova-translatable

A Laravel Nova package that allows you to make any input field translatable.
MIT License
197 stars 55 forks source link

Doesn't save translations with Nova repeater #106

Open Arturas0 opened 11 months ago

Arturas0 commented 11 months ago

When I use a translatable Text field in Repeater component, translatable field information is not saved to json field, instead it saves as null.

Nova field in resource:

 BelongsToMany::make('Professionals', 'professionals', Professional::class)->fields(static function () {
                    return [
                        Repeater::make('Role with dates', 'dates')
                            ->repeatables([
                                RoleWithDates::make(),
                            ])
                            ->asJson()
                    ];
                })

Repeater component code:

class RoleWithDates extends Repeatable
{
    public function fields(NovaRequest $request): array
    {
        return [
            Text::make('Role')
                ->nullable()
                ->translatable(),

            Date::make('Start date', 'start')
                ->rules('nullable', 'date')
                ->resolveUsing(function ($value) {
                    return $value;
                }),

            Date::make('End date', 'end')
                ->rules('nullable', 'date', 'before_or_equal:today')
                ->resolveUsing(function ($value) {
                    return $value;
                }),
        ];
    }

If I fill information in database directly, then translatable Text field can display information without problem.

Working json example:

[{"type": "role-with-date", "fields": {"end": "2023-09-10", "role": {"en": "swimmer", "lt": "plaukikas", "pl": "", "ru": ""}, "start": "2023-09-01"}}] rolw with text translatable

As temporary solution I use KeyValue field, as it saves information in json correctly. role with dates workaround

I'm using the following:

Laravel framework 10.25.1 Nova 4.27.13 PHP 8.2 Nova translatable 2.2.0

wajdijurry commented 11 months ago

Maybe this would help: https://github.com/emilianotisato/nova-tinymce/issues/62

cereneto commented 6 months ago

Same issue here.