ștef
ștef
FFilament
Created by ștef on 7/28/2024 in #❓┊help
Change filament html element class definition dynamically
Hi. Check this SO post if possible: https://stackoverflow.com/questions/78803565/filament-add-extra-class-to-the-html-element-dynamically I have a FileElement and I would like to add a class to it dynamically based on some properties. For example, take this piece of code:
public static function makeImageFileUpload(
string $name,
string $directory = 'profiles/images',
string $visibility = 'public',
): FileUpload {
return FileUpload::make($name)
->image()
->imageEditor()
->imageEditorAspectRatios(['9:16'])
->disk($visibility)
->directory($directory)
->visibility($visibility)
->downloadable()
->openable()
->deletable()
->live()
->extraAttributes(function (FileUpload $component, Get $get) use ($name): array {
$fileCount = $component->isMultiple() ? $component->getMaxFiles() : 1;
Log::info($name, ['maxCount' => $fileCount, 'actualCount' => count($get($name))]);
if ($fileCount === count($get($name))) {
Log::info($name . ' hidden');
return ['class' => 'file-upload-hidden'];
} else {
Log::info($name . ' visible');
return ['class' => 'file-upload-visible'];
}
})
;
}
public static function makeImageFileUpload(
string $name,
string $directory = 'profiles/images',
string $visibility = 'public',
): FileUpload {
return FileUpload::make($name)
->image()
->imageEditor()
->imageEditorAspectRatios(['9:16'])
->disk($visibility)
->directory($directory)
->visibility($visibility)
->downloadable()
->openable()
->deletable()
->live()
->extraAttributes(function (FileUpload $component, Get $get) use ($name): array {
$fileCount = $component->isMultiple() ? $component->getMaxFiles() : 1;
Log::info($name, ['maxCount' => $fileCount, 'actualCount' => count($get($name))]);
if ($fileCount === count($get($name))) {
Log::info($name . ' hidden');
return ['class' => 'file-upload-hidden'];
} else {
Log::info($name . ' visible');
return ['class' => 'file-upload-visible'];
}
})
;
}
What happens is that the extraAttributes method gets invoked when I change the FileUpload data in the form, however it does not update. It initially renders with the class that matches the logic, but if that changes, it does not add/remove any other classes. It's like the class property of the html element is only set during the first render, and any other changes to it are ignored. Is there anything I could do about it?
8 replies
FFilament
Created by ștef on 3/7/2024 in #❓┊help
Subfroms /sections with individual actions
I am structuring my complex form using sections and I would like to do separate updates, section by section. However, I observed that an action attached to a section from the main from triggers the entire from submit. Is there any strategy or any recommended way to have multiple forms/subfroms in the same page? For example: I have a section Profile Info, and another Profile Media. I would like to have them on the same page, but each section with it's own action and independed calls to the db.
2 replies
FFilament
Created by ștef on 3/7/2024 in #❓┊help
Section has no footer actions?
According to the docs: https://filamentphp.com/docs/3.x/forms/layout/section#adding-actions-to-the-sections-footer, there should be some footer actions method. However, I am not able to locate that in v3.2.
5 replies
FFilament
Created by ștef on 2/29/2024 in #❓┊help
Create a de-CH localization folder
I want to create a de-CH folder for localization, but I did not manage to find the right path to override the locale from filament as per the docs. Is there any example on how to achieve that?
2 replies