Bashar El-Mouhammad
Bashar El-Mouhammad

Reputation: 59

Dynamically change form fields in Filament Laravel

Is it possible to generate new fields in a form based on a checkBoxList in filament dynamically, Lets say I have a product and I checked the color option on it then an input field appear to add the value to that color.

Thanks in advance.

Upvotes: 1

Views: 19290

Answers (3)

Saeed Kiarsi Zadeh
Saeed Kiarsi Zadeh

Reputation: 87

If you want hidden from a user that is not admin (is_admin column is 0):

Toggle::make('column')->hidden(fn(callable $get) => Auth::user()->is_admin == 0);

Of course that you have create column name is_admin(tinyint or boolean) to do this

Upvotes: 0

dfun
dfun

Reputation: 33

A little late on this, but I did it making the hidden property change dynamically.

Toggle::make('column')->hidden(function (callable $get) {
    if ($get('other_column') == 'x') {
        return false;
    } else {
        return true;
    }
})

The 'other_column' must have the reactive() method.

Upvotes: 3

Khalil Majdalawi
Khalil Majdalawi

Reputation: 111

yes, you can use Dependent fields

Upvotes: 2

Related Questions