Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make optionsLabel able to use nested object key #40

Closed

Conversation

ahmedsayedabdelsalam
Copy link

@ahmedsayedabdelsalam ahmedsayedabdelsalam commented Jul 17, 2020

I use spatie translation package and I think many of us do

the translation columns are of json datatype like name = {"en": "dog", "de": "hund"}

I find that the form select input works well but the index and details pages are not working optionsLable('name')
Screen Shot 2020-07-17 at 1 57 36 AM

also when setting optionsLabel like this optionsLabel('name.en')
Screen Shot 2020-07-17 at 1 57 17 AM

I know we could make a computed attribute for that but it's painful to add those custom attributes everywhere.

I think making it can access nested key from object like optionsLabel('name.en') well be very helpful
Screen Shot 2020-07-17 at 1 55 09 AM

@Benjacho
Copy link
Owner

First of all thank you for your contribution, could you make Readme about this? after that i will be able to merge this

@Benjacho Benjacho added the to-review This solution seems to work label Jul 22, 2020
@ahmedsayedabdelsalam
Copy link
Author

First of all thank you for your contribution, could you make Readme about this? after that i will be able to merge this

done ✅

@Benjacho Benjacho mentioned this pull request Aug 21, 2020
@SimonBarrettACT
Copy link

SimonBarrettACT commented Aug 26, 2020

This doesn't seem to fix the issue in FormField.

@ahmedsayedabdelsalam
Copy link
Author

@SimonBarrettACT make sure you use the LogsActivit trait.
and add protected $translatable = ['title']; to the model.
and make sure that the values used to represent the resource it title
Screen Shot 2020-08-27 at 5 16 37 PM
Screen Shot 2020-08-27 at 5 15 42 PM
Screen Shot 2020-08-27 at 5 15 00 PM

@SimonBarrettACT
Copy link

My model was already set up as you suggested and this is my field entry:

BelongsToManyField::make('Towns', 'towns', 'App\Nova\Town')->optionsLabel('name.en')

but nothing is being displayed.

@SimonBarrettACT
Copy link

SimonBarrettACT commented Aug 27, 2020

I'm not sure what you mean by:

@SimonBarrettACT make sure you use the LogsActivit trait.

@ahmedsayedabdelsalam
Copy link
Author

Sorry, my mistake I meant the trait in the model as shown in the picture

I am not sure why it is not working with you
But I rechecked the code again an it's working with me.

@SimonBarrettACT
Copy link

It's strange. I can't see why it isn't working either. Thanks for your efforts to help though.

@ahmedsayedabdelsalam
Copy link
Author

I wish I could help,
can you send me those files to e.eng.ahmedsayed@gmail.com I'll try debugging this issue in my project?
if you're ok with that.
I need those files.
models and nova resources for the two sides of the relation.

@LouisHrg
Copy link

LouisHrg commented Sep 8, 2020

Hello !
I tried your fork and it works well, except on editing, i don't have any label displayed
image

@ahmedsayedabdelsalam
Copy link
Author

@LouisHrg
at "create" form when you select something is it also appears like that?

@LouisHrg
Copy link

LouisHrg commented Sep 8, 2020

Nope it works fine, I'll try to fix the issue in a PR today, the issue seems to be in setInitialValue in FormField.vue

Update : here's the PR ahmedsayedabdelsalam#1

let me know 👍

@SimonBarrettACT
Copy link

I was having the same issue and have submitted a pull request #54 that fixes the issue by providing the ability to set the language used.

@ahmedsayedabdelsalam
Copy link
Author

ahmedsayedabdelsalam commented Oct 9, 2020

Nope it works fine, I'll try to fix the issue in a PR today, the issue seems to be in setInitialValue in FormField.vue

Update : here's the PR ahmedsayedabdelsalam#1

let me know 👍

@LouisHrg
sorry for the late reply. your PR fixes the issue. Thank you.

@SimonBarrettACT kindly recheck if it works now.

@SimonBarrettACT
Copy link

It works for me thanks.

@ahmedsayedabdelsalam
Copy link
Author

@SimonBarrettACT Great 👌

@Benjacho waiting for your review.

@manyasone
Copy link

Works perfectly fine for me, too. Any chance this will be merged to the main repo in the near future? ;)

@Benjacho
Copy link
Owner

Already merged ty

@Benjacho Benjacho closed this Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-review This solution seems to work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants