nova-inline-select icon indicating copy to clipboard operation
nova-inline-select copied to clipboard

Inline select of a related entity field

Open andypooletrioteca opened this issue 5 years ago • 2 comments

I'm trying to use the component to update a related entity but i'm beginning to feel this is not possible.

Basically i'm trying to do something like this:

            InlineSelect::make('Status', 'relatedStuff.status')
                ->options(RelatedStuff::STATUS_NAMES)
                ->displayUsingLabels()->inlineOnIndex()->disableTwoStepOnIndex(),

The status list displays correctly but the value doesn't get updated when i change it.

Any guidelines on how to approach this development? i could try to do a pull request with this.

andypooletrioteca avatar Mar 23 '20 16:03 andypooletrioteca

Thanks for the suggestion @andypooletrioteca.

Feel free to issue a PR for this addition. Thanks!

brandonferens avatar Mar 24 '20 16:03 brandonferens

@andypooletrioteca Not sure if I understand you correctly. But I'm using the below workaround (I'm using Spatie's Status).

What I did is check in an Observer (Model::observe(ModelObserver::class)) in the updating event if the field is set, then update the related entity and unset the field. Like this:

InlineSelect::make('Status', 'inline_status')
                ->options(RelatedStuff::STATUS_NAMES)
                ->displayUsingLabels()->inlineOnIndex()->disableTwoStepOnIndex(),

In the Observer:

public function updating($model)
    {
        if(isset($model->inline_status)){
            $model->setStatus($model->inline_status);
            unset($model->inline_status);
        }
    }

Paulsky avatar May 20 '20 15:05 Paulsky