outl1ne/nova-translatable

Doesn't save translations with Nova repeater

Arturas0 opened this issue · 2 comments

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

Maybe this would help:
emilianotisato/nova-tinymce#62

Same issue here.