F
Filament•3w ago
tuseto

Filament repeater translations messed up structure on save

When create repeater first row for the model on bg language the result in the db is: {"bg":[{"name":"first","slug":"first"}],"de":""} Adding second row for same language is okay and the result is: {"bg":[{"name":"first","slug":"first"},{"name":"second","slug":"second"}],"de":""} Then when change the language to en and add the first row in the repeater everything breaks: {"bg":{"d6073341-870a-43f3-bb83-8c49d4df16bf":{"name":"first","slug":"first"},"38b95945-88e1-462b-9e8c-469766af5baf":{"name":"second","slug":"second"}},"en":[{"name":"english_first","slug":"english_first"}]} Composer.lock filament/filament: version: v3.2.121 filament/spatie-laravel-translatable-plugin: v3.3.0 repositories: https://github.com/lara-zeus/translatable (I am using lara-zeus fork of filament-translatable, because as I remember I have problems with file upload for different languages on the original filament-translatable repo) I have a repeater:
Repeater::make('files')
->schema([
TextInput::make('name')->required(),
TextInput::make('slug')->required(),
// FileUpload::make('file'),
])
->columns(2),
Repeater::make('files')
->schema([
TextInput::make('name')->required(),
TextInput::make('slug')->required(),
// FileUpload::make('file'),
])
->columns(2),
files is in my model $translatable fields files is cast as array 'files' => 'array', All model translations works as expected but repeater not.
GitHub
GitHub - lara-zeus/translatable: A Fork of the Filament spatie/lara...
A Fork of the Filament spatie/laravel-translatable Plugin - lara-zeus/translatable
5 Replies
Lara Zeus
Lara Zeus•3w ago
I have repeater in the demo https://github.com/lara-zeus/translatable-demo/blob/213d9895c3dfbb66dde509e045e3e899687516c2/app/Filament/Resources/BookResource.php#L50
{"en":{"1898ef07-2bfc-463a-9775-6b6892966232":{"name":"sdf"},"702f07f8-762c-41b2-b7d1-72c49b521252":{"name":"sdf"}},"es":[{"name":"sdf"}]}
{"en":{"1898ef07-2bfc-463a-9775-6b6892966232":{"name":"sdf"},"702f07f8-762c-41b2-b7d1-72c49b521252":{"name":"sdf"}},"es":[{"name":"sdf"}]}
but still filament can handle them
tuseto
tusetoOP•3w ago
Yes, filament handles them. I've just noticed this when my client side throws an exception because of unprocessable data. Then I've found the change in the structure in the json column on save. I just didn't know if is this changes occuring for different languages are expected to happen. And if there is a problem or not. So as it seems it is supposed to work this way. I appriciate your quick answer! Thank you!
Lara Zeus
Lara Zeus•3w ago
I'll give it more test this weekend and see if its possible to fix it 🙂 it seems it adds the UUID keys on the first lang only can you check if its happens on create only or on edit also?! since these are diff classes.
tuseto
tusetoOP•3w ago
Tomorrow will test more in depth, because it seems that the problem is not only on the first lang, nor the default one. And maybe there is something with the sequence of the actions on different language. Hope will find a patter and will write it here 🙂 Hope this will help 🙂 It is a bit hard to explain it cleaner. 1. Hitting save button will result in no hash for current language repeater data and hash added for all of the rest langs (if they are not just empty arrays). 2. This is true for both create and edit actions (when creating you traverse languages and fill the data, hit save, same will happen, current language will be without hash, all others will have) 3. Having a repeater for a lang or not, doesn't matter, because even if you don't have a repeater for a lang it is saved as empty array by default, so hashes are added for the rest of the languages. 4. Didn't found dependency with default language for the cases above. 5. Default language matters in one case - edit without repeater only in one language By default editing on every language without repeater adds empty array as data. Saving in non default language, adds the default language automatically and assigns it empty array. (bg is default) like this: {"en":[],"bg":[]} But saving in default language without repeater adds empty string for don't know how picked language in that case 'de'. (every time when this occurs the string is for 'de' language) {"bg":[],"de":""} This is not a problem and maybe never will be. I've just noticed it. You can create a resource on default lang it will be {"bg":[]} after creating just hit save and: {"bg":[],"de":""} P.S. Some similar issue is happening to files inside the repeater. Sometimes they become: "file":{"f56d1d23-f291-4166-9002-8101b2977e40":"01JBHD5YSK0NMAEP5BXHC9ABFA.pdf"} but they should be: "file":"01JBHD8PWFENG72F7XNABSJ061.pdf"
Philipp BĂĽrger
Philipp Bürger•5d ago
Anything updates here? Facing the same issue with a fileupload. Filament handles it fine but in the frontend its not that nice to have different data formats. I remember that this bug existed a while ago but was fixed ..
Want results from more Discord servers?
Add your server