0
votes

I'm making a create form for one of my resources using Nova. Some of the fields have conditional relationships to one another.

For example: if "is trial" is selected we must specify a value for "trial end date", but there's no point showing the "end date" field on the page if "is trial" isn't picked. Another example, fields A and B are mutually exclusive.

All of these can easily be enforced with conditional validators in the backend, and I know how to do that. I'm just trying to make an interface that's not confusing.

How can I customize the frontend JS forms for this resource to reflect such conditional relationships?

1

1 Answers

1
votes
Its possible using this one

// put this inside     **public function fields(Request $request)**
BelongsTo::make('Subcategoria', 'subcategory', 'App\Nova\SubCategory'),

 // conditional display
 $this->sellerFields(),


//used for conditional seller input 
    protected function sellerFields()
    {
        if(\Auth::user()->role == "admin"){
            return $this->merge([
                BelongsTo::make('Vendedor', 'user', 'App\Nova\User'),
            ]);
        }else{
            return $this->merge([]);
        }
    }