eazy
eazy
FFilament
Created by eazy on 11/3/2023 in #❓┊help
Nested RepeatableEntry shows duplicate values from first relation
No description
3 replies
FFilament
Created by eazy on 8/16/2023 in #❓┊help
Dispatch on table row click
I want to dispatch a event when a Table row is clicked.
->recordAction(fn () => $this->dispatch('openFillAction'))
->recordAction(fn () => $this->dispatch('openFillAction'))
I tried using the recordAction but that doesn't seem to work. Is there another easy way I can do this?
4 replies
FFilament
Created by eazy on 7/27/2023 in #❓┊help
Actions error in Infolist
I have the a infolist with 2 cards which are conditionally displayed. They both have different actions. When I do the start_configuration action the card gets hidden and the other card gets displayed. But when I want to click the close_configuration action I get a javascript error in my console. The action only works when I refresh, how can I fix this?
15 replies
FFilament
Created by eazy on 7/26/2023 in #❓┊help
Open an action from another action
I have the following InfoListAction:
Actions::make([
Action::make('close_configuration')
->extraModalFooterActions(fn(Action $action): array => [
$action
->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('machine-configurations.close and create new'))
->color('success'),
])
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
if ($record->activeMachineConfiguration === null) {
return false;
}

$closed = $closeMachineConfiguration($record->activeMachineConfiguration);

if (!$closed) {
$action->sendFailureNotification();
}

if ($closed) {
$action->sendSuccessNotification();
}

if (isset($arguments['another']) && $arguments['another']) {

}

return $closed;
})
])->fullWidth()
Actions::make([
Action::make('close_configuration')
->extraModalFooterActions(fn(Action $action): array => [
$action
->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('machine-configurations.close and create new'))
->color('success'),
])
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
if ($record->activeMachineConfiguration === null) {
return false;
}

$closed = $closeMachineConfiguration($record->activeMachineConfiguration);

if (!$closed) {
$action->sendFailureNotification();
}

if ($closed) {
$action->sendSuccessNotification();
}

if (isset($arguments['another']) && $arguments['another']) {

}

return $closed;
})
])->fullWidth()
Now when the another argument is set I want to open another action that is declared down later on
22 replies
FFilament
Created by eazy on 5/17/2023 in #❓┊help
Spatie Media Library File Upload replacing every uploaded file
Hello, I have created a custom action for a file upload to my table, but when I upload a file it replaces all the already uploaded files. This hasn't been happening before. After going through the code I found out the deleteAbandonedFiles() method in the plugin, this gets called in the saveRelationshipUsing() method. It looks to me that only the uploaded file UUID gets added to the state so the rest of the files get deleted. But I'm not sure how to fix this. My custom action:
protected function setUp(): void
{
parent::setUp();

// $this->authorize('upload-file');

$this->label(__('filemanager.upload file'));

$this->modalButton(__('filemanager.upload file'));

$this->modalHeading(__('filemanager.upload file'));

$this->button();

$this->successNotificationTitle(__('filemanager.file uploaded'));

$this->icon('tabler-file-upload');

$this->form(function () {
$field = SpatieMediaLibraryFileUpload::make('file')
->model($this->record)
->disableLabel()
->required()
->multiple()
->minFiles(1)
->maxSize(500_000); // 500mb

$acceptedFileTypes = $this->getAcceptedFileTypes();

if (!empty($acceptedFileTypes) && $acceptedFileTypes !== null) {
$field->acceptedFileTypes($acceptedFileTypes);
}

return [$field];
});

$this->action(fn(UploadFilesAction $action) => $action->success());
}
protected function setUp(): void
{
parent::setUp();

// $this->authorize('upload-file');

$this->label(__('filemanager.upload file'));

$this->modalButton(__('filemanager.upload file'));

$this->modalHeading(__('filemanager.upload file'));

$this->button();

$this->successNotificationTitle(__('filemanager.file uploaded'));

$this->icon('tabler-file-upload');

$this->form(function () {
$field = SpatieMediaLibraryFileUpload::make('file')
->model($this->record)
->disableLabel()
->required()
->multiple()
->minFiles(1)
->maxSize(500_000); // 500mb

$acceptedFileTypes = $this->getAcceptedFileTypes();

if (!empty($acceptedFileTypes) && $acceptedFileTypes !== null) {
$field->acceptedFileTypes($acceptedFileTypes);
}

return [$field];
});

$this->action(fn(UploadFilesAction $action) => $action->success());
}
18 replies
FFilament
Created by eazy on 4/18/2023 in #❓┊help
Redirect in listener
Hello, I'm making a custom listener to download a PDF when someone clicks on a button. The PDF gets generated on a URL so I want to redirect the user to the url when they click on the button. But it doesn't work. This is the current code:
$this->registerListeners(['repeater::downloadItem' => [
function (Repeater $component, string $statePath, string $idToDownload) {
if ($statePath !== $component->getStatePath()) {
return;
}

$record = $component->getRecord();
$id = Str::after($idToDownload, '-');

return redirect()->route('requests.pdf', [$record, false, [$id]]);
}
]]);
$this->registerListeners(['repeater::downloadItem' => [
function (Repeater $component, string $statePath, string $idToDownload) {
if ($statePath !== $component->getStatePath()) {
return;
}

$record = $component->getRecord();
$id = Str::after($idToDownload, '-');

return redirect()->route('requests.pdf', [$record, false, [$id]]);
}
]]);
8 replies
FFilament
Created by eazy on 3/10/2023 in #❓┊help
Dynamic text input value
I have the following form:
return [
TextInput::make('year')
->label(__('Year'))
->numeric()
->reactive()
->required(),
TextInput::make('name')
->label(__('Name'))
->numeric()
->reactive()
->required(),
TextInput::make('code')
->reactive()
->afterStateHydrated(function (TextInput $component, Closure $get) {
$year = $get('year');
$name = $get('name');
if ($year !== null && $name !== null) {
$component->state('xxx');
}
$component->state('123');
})
->disabled()
];
return [
TextInput::make('year')
->label(__('Year'))
->numeric()
->reactive()
->required(),
TextInput::make('name')
->label(__('Name'))
->numeric()
->reactive()
->required(),
TextInput::make('code')
->reactive()
->afterStateHydrated(function (TextInput $component, Closure $get) {
$year = $get('year');
$name = $get('name');
if ($year !== null && $name !== null) {
$component->state('xxx');
}
$component->state('123');
})
->disabled()
];
I want my code field's value change when the year and name input gets a value. If the year and name input is empty I want to show nothing. How can I achieve this?
7 replies