© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
33 replies
Pekempy

BulkActions - Copy multiple rows to clipboard

I've got a custom Action that extends BulkAction, and I'm using
$this->dispatch
$this->dispatch
to send the data for the clipboard to the client:
(this is in the
->action()
->action()
)
foreach ($records as $record) {
    //copy to clipboard logic
    $showName = $record->show->name;
    $tourName = $record->production->name;
    $date = $record->clipboardDate;
    $this->clipboard .= "$showName - $tourName - $date\n";
}
$this->dispatch('copy-to-clipboard', [$this->clipboard]);
foreach ($records as $record) {
    //copy to clipboard logic
    $showName = $record->show->name;
    $tourName = $record->production->name;
    $date = $record->clipboardDate;
    $this->clipboard .= "$showName - $tourName - $date\n";
}
$this->dispatch('copy-to-clipboard', [$this->clipboard]);

This works fine - ish. It only uses the data from the previous time you ran bulk action, rather than waiting for the foreach to finish it seems the dispatch is running first, even though it should be synchronous?

The js in my blade file is:
<div x-data="{
    copyToClipboard(event) { 
        console.log(event.detail);
        navigator.clipboard.writeText(event.detail);
    }
}" 
x-on:copy-to-clipboard.window="copyToClipboard">
</div>
<div x-data="{
    copyToClipboard(event) { 
        console.log(event.detail);
        navigator.clipboard.writeText(event.detail);
    }
}" 
x-on:copy-to-clipboard.window="copyToClipboard">
</div>


Any ideas why this dispatch is running before the foreach loop ends, or how I can achieve this another way?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Copy to clipboard on TextInput
FilamentFFilament / ❓┊help
3y ago
Copy to clipboard action table
FilamentFFilament / ❓┊help
3y ago
Action button - copy to clipboard
FilamentFFilament / ❓┊help
3y ago
Copy to clipboard table row action
FilamentFFilament / ❓┊help
3y ago