F
Filament15mo ago
alek

How to set (this) value for an action? What about form builder field?

My issue is this. I want an action that works on "this" field. I don't want to explicitly define the title in the $set method, because A). There will be multiple fields of this kind and B). I'd rather do $set('this', $value) without explicitly specifying the title. How do you solve this?
class MyCoolAction
{
static function make($name, $componentToChange)
{
return Action::make($name)
->icon('heroicon-s-sparkles')
->color('primary')
->action(function (Set $set, $state) use ($componentToChange) {
$set($componentToChange, 'Hello World');
});
}
}
class MyCoolAction
{
static function make($name, $componentToChange)
{
return Action::make($name)
->icon('heroicon-s-sparkles')
->color('primary')
->action(function (Set $set, $state) use ($componentToChange) {
$set($componentToChange, 'Hello World');
});
}
}
In the above example, my custom class just encapsulates the details of this function. I add it to a form component, and pass in the name. But, if I have multiple actions attached to multiple components in a Form Builder, the names will repeat. Does this action then change them ALL? I don't know how to do something like $set(this, 'Hello World') instead of explicitly defining the name.
Solution:
Edit: Figured this out. If you pass the name of the component, even if you have multiple, it will only affect the group you are working in. So having multiple hero components for instance, will only change the one you are invoking. It is hurting my brain a bit but it works....
Jump to solution
1 Reply
Solution
alek
alek15mo ago
Edit: Figured this out. If you pass the name of the component, even if you have multiple, it will only affect the group you are working in. So having multiple hero components for instance, will only change the one you are invoking. It is hurting my brain a bit but it works.
Want results from more Discord servers?
Add your server