orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

Meta data value not working #37

Closed lvdhoorn closed 5 years ago

lvdhoorn commented 5 years ago

When you trying to set a default value with the withMeta function the data seems to be ignored.

For examle


NovaBelongsToDepend::make('Company')
                        ->options(Company::all())
                        ->fillUsing(function(){})
                        ->withMeta(
                            [
                                'belongsToId'   =>  2
                            ]),
`
dtannen commented 5 years ago

Is there a way to set the default value? withMeta() doesn't exist: https://github.com/orlyapps/nova-belongsto-depend/blob/master/src/NovaBelongsToDepend.php

novocent commented 5 years ago

Any ideas? It works great for me on new records or changing data, however I can't see how to select the proper value if it is already assigned.

novocent commented 5 years ago

I worked out my issues. Sorry for the post.

orlyapps commented 5 years ago

Hello, Default value works like this. Not very ideal and confusion but it works. NovaBelongsToDepend::make('Unternehmen', 'company', \App\Nova\Company::class) ->withMeta(['value' => $this->company ?? \Auth::user()->company, 'valueKey' => $this->company->id ?? \Auth::user()->company->id]) ->options(\App\Company::all()) ->onlyOnForms() ->rules('required'),

Milkhan commented 4 years ago

@orlyapps Thank you! This works but when I use this within Conditional Container (https://github.com/dcasia/conditional-container) it comes with the default value but the dependent field doesn't populate(Its hidden by default, I need to change a value in another field to make it visible). I need to select another value then reselect the default value to trigger the dependent population. Any ideas?