create a button or action that copy a value from another field

Hello, i want to ask how to make a button/action that copy a value to field itself that inside repeater.
->action(function (Get $get, Set $set) {
return $set('instituteNameParticipant',$get('instituteName'))
})
->action(function (Get $get, Set $set) {
return $set('instituteNameParticipant',$get('instituteName'))
})
i make like this but not working Thank you for your help!
Solution:
Since you are in a repeater you have to traverse out of it for fields that aren’t in it. $set(‘../instituteName’)
Jump to solution
25 Replies
BlackShadow
BlackShadow8mo ago
Get $get on a suffix action?
JJSanders
JJSanders8mo ago
Can you shware a bit more code ?
BlackShadow
BlackShadow8mo ago
// https://filamentphp.com/docs/3.x/forms/actions#defining-a-form-component-action
TextInput::make('cost')
->prefix('€')
->suffixAction(
Action::make('copyCostToPrice')
->icon('heroicon-m-clipboard')
->requiresConfirmation()
->action(function (Set $set, $state) {
$set('price', $state);
})
)
TextInput::make('cost')
->prefix('€')
->suffixAction(
Action::make('copyCostToPrice')
->icon('heroicon-m-clipboard')
->requiresConfirmation()
->action(function (Set $set, $state) {
$set('price', $state);
})
)
Not tested 👀 First you get then you set? Make sure you target the correct repeater.
JJSanders
JJSanders8mo ago
Hehe I needed something like this for something in my project. Was expecting that this action would copy to the clipboard but it doesn't
BlackShadow
BlackShadow8mo ago
Take a look at this code its a bit older bit might be what you are looking for; https://github.com/webbingbrasil/filament-copyactions/blob/3.x/src/Concerns/HasCopyable.php
GitHub
filament-copyactions/src/Concerns/HasCopyable.php at 3.x · webbingb...
A easy-to-use copy actions for Filament Admin Pages, Tables and Form Fields. - webbingbrasil/filament-copyactions
BlackShadow
BlackShadow8mo ago
No description
BlackShadow
BlackShadow8mo ago
👀
JJSanders
JJSanders8mo ago
Trying to work out how it should work. I am using it on a select
BlackShadow
BlackShadow8mo ago
->hintAction(function (Get $get) {
return Forms\Components\Actions\Action::make('Copy')
->icon('heroicon-s-clipboard')
->action(function ($livewire, $state) {
$livewire->js('
navigator.clipboard.writeText("YOUR_TEXT"); $tooltip("Copied to clipboard", { timeout: 1500 });
');
});
}),
->hintAction(function (Get $get) {
return Forms\Components\Actions\Action::make('Copy')
->icon('heroicon-s-clipboard')
->action(function ($livewire, $state) {
$livewire->js('
navigator.clipboard.writeText("YOUR_TEXT"); $tooltip("Copied to clipboard", { timeout: 1500 });
');
});
}),
Something like this
JJSanders
JJSanders8mo ago
I tried using your plugin but it looks like it is broken
BlackShadow
BlackShadow8mo ago
What
JJSanders
JJSanders8mo ago
GitHub
Method Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction::...
Hi. I'm getting a Method Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction::getDefaultCopyable does not exist exception when I try and use ->copyable in a TextInput suffix action: -...
BlackShadow
BlackShadow8mo ago
Thats not mine Just a suggestion
JJSanders
JJSanders8mo ago
Ah I thought it was yours sorry When I try this I am getting the error Class "Forms\Components\Actions\Action" not found
BlackShadow
BlackShadow8mo ago
😅
JJSanders
JJSanders8mo ago
Got it working:
->suffixAction(function (Get $get) {
return Action::make('Copy')->icon('heroicon-s-clipboard')->action(function ($livewire, $record) {
$texToCopy = null;
$product = $record?->product;
if ($product) {
$texToCopy = $product->supplier_code ?? $product->item_code;
}
$livewire->js('navigator.clipboard.writeText("' . $texToCopy . '"); $tooltip("Copied to clipboard", { timeout: 1500 });');
});
})
->suffixAction(function (Get $get) {
return Action::make('Copy')->icon('heroicon-s-clipboard')->action(function ($livewire, $record) {
$texToCopy = null;
$product = $record?->product;
if ($product) {
$texToCopy = $product->supplier_code ?? $product->item_code;
}
$livewire->js('navigator.clipboard.writeText("' . $texToCopy . '"); $tooltip("Copied to clipboard", { timeout: 1500 });');
});
})
The tooltip is not yet working though It seems to work. Just the tooltip appears somewhere random
BlackShadow
BlackShadow8mo ago
Remkve the tooltip and add a custom notification
thyk123
thyk1238mo ago
Hello, thank you for all your respond @CodeWithDennis @JJSanders, you people are so awesome I mean i want to make an action that copy to itself like this code below
//this is outside repeater
TextInput::make('instituteName')->required(),

//this is inside repeater
TextInput::make('instituteNameParticipant')
->suffixAction(
Action::make('copyCostToPrice')
->icon('heroicon-m-clipboard')
->requiresConfirmation()
->action(function (Set $set, Get $get, $state) {
$set('instituteNameParticipant', $get('instituteName'));
})
)
->required(),
//this is outside repeater
TextInput::make('instituteName')->required(),

//this is inside repeater
TextInput::make('instituteNameParticipant')
->suffixAction(
Action::make('copyCostToPrice')
->icon('heroicon-m-clipboard')
->requiresConfirmation()
->action(function (Set $set, Get $get, $state) {
$set('instituteNameParticipant', $get('instituteName'));
})
)
->required(),
but i think this code is wrong
JJSanders
JJSanders8mo ago
What do you mean by 'copy to itself'?
thyk123
thyk1238mo ago
@JJSanders i mean the action button (instituteNameParticipant) do a copy from (instituteName) value and change the value of (instituteNameParticipant) value
JJSanders
JJSanders8mo ago
I think your issue is in this line: $set('instituteNameParticipant', $get('instituteName'));
thyk123
thyk1238mo ago
@JJSanders yes i mean, i want the action instituteNameParticipant get the value from instituteName field and copy the value to instituteNameParticipant field Hmm,it doesn't seem like it can do that way right?
JJSanders
JJSanders8mo ago
Just dump the values to check what you get. First dump the get.
Solution
awcodes
awcodes8mo ago
Since you are in a repeater you have to traverse out of it for fields that aren’t in it. $set(‘../instituteName’)
thyk123
thyk1238mo ago
THANK YOU SO MUCH this is work hahah. I need traverse 2 times since inside wizard too. @JJSanders @CodeWithDennis thank you for your concern and respond for this question! i really appriciate for both of your work! @awcodes @JJSanders @CodeWithDennis Have a nice day!
Want results from more Discord servers?
Add your server