outl1ne / nova-translatable

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

Do not cast string 0 to float within Text field #115

Closed robertmarney closed 1 month ago

robertmarney commented 8 months ago

We ran into an issue where nova-translatable was casting user provided string 0 to float before it was serialized to send to the front end.

Unlike PHP, JS (Vue that renders) considers float 0 as falsy and is not rendering in some fields. How this was manifesting is user was providing a 0 value within the text field and it would save, upon view / edit the field would be presented as empty.

image

Proposed change would cast values within a Text field (but not Number as Number extends Text) to a string which I think is logical as a translation of a text field should be considered a string type.

robertmarney commented 8 months ago

@Tarpsvo - I wanted to check in and see if this is something that will be considered. Thanks!

KasparRosin commented 1 month ago

@robertmarney Hey! Pulled the latest release with this commit included and ran into an issue. Namely when in database, translatable json column value is as such {"en": ""}, the Text field will throw the following error.

exception: "ErrorException"
file:"/vendor/outl1ne/nova-translatable/src/TranslatableFieldMixin.php"
line: 80
message: "foreach() argument must be of type array|object, string given"

The field is the most basic.

Text::make('My Column')
  ->translatable(),
KasparRosin commented 1 month ago

image image

The first image shows dd($value) when database has {"en": ""} The second image shows dd($value) when database has {"en": "abc"}

I'd say that the issue relies somewhere else, but you just happened to stumble upon it 😅

KasparRosin commented 1 month ago

Fixed via #133