ziffmedia / nova-select-plus

A Laravel Nova Select Field
MIT License
95 stars 26 forks source link

Callable in SelectPlus::label() #6

Closed pecuchet closed 4 years ago

pecuchet commented 4 years ago

Hi thanks for the useful package! I would like to customize label in the vue-select field, much in the same way as for usingDetailLabel and usingIndexLabel. That is, passing a callback to SelectPlus::label() and being able to build a custom string from it. Field::displayUsing() does not seem to work here. Any ideas?

I played around by adding this method to SelectPlus:

protected function getValueFromLabel($model){
        return is_callable($this->label)
            ? call_user_func($this->label, $model)
            : $model->{$this->label};
}

and changing $model->{$this->label} to $this->getValueFromLabel($model) in SelectPlus::mapToSelectionValue(). It works, except when doing an ajax search...

ralphschindler commented 4 years ago

is this ok in 1.0.5?

ralphschindler commented 4 years ago

Closing issue for now, can reopen if not solved in latest version

pecuchet commented 4 years ago

Great, it works - thanks!