christhompsontldr
christhompsontldr
FFilament
Created by christhompsontldr on 8/2/2024 in #❓┊help
Limiting validation rules
I have a single form with multiple sections. I declare the validation rules for each field via the ->rules() method. I would like to only process the validation rules for the section that the action button was pressed in. I have reasons for using ->rules() instead of Filaments helper methods like ->string(). In the following code, when the personal_action button is pressed, I want to validate name but not company_name. Or, when the business_action is pressed, I want to validate company_name but not name. Is there a way to accomplish with Filament?
public function form(Form $form): Form
{
return $form->schema([
Section::make('personal')
->schema([
TextInput::make('name')
->rules(['max:20', 'required']),
Actions::make([
Action::make('personal_action')
->action(function (Set $set) {
$this->form->getState();

doSomethingMagical();
}),
]),
]),
Section::make('business')
->schema([
TextInput::make('company_name')
->rules(['max:20', 'required']),
Actions::make([
Action::make('business_action')
->action(function (Set $set) {
$this->form->getState();

doSomethingMagical();
}),
]),
]),
]);
}
public function form(Form $form): Form
{
return $form->schema([
Section::make('personal')
->schema([
TextInput::make('name')
->rules(['max:20', 'required']),
Actions::make([
Action::make('personal_action')
->action(function (Set $set) {
$this->form->getState();

doSomethingMagical();
}),
]),
]),
Section::make('business')
->schema([
TextInput::make('company_name')
->rules(['max:20', 'required']),
Actions::make([
Action::make('business_action')
->action(function (Set $set) {
$this->form->getState();

doSomethingMagical();
}),
]),
]),
]);
}
2 replies
FFilament
Created by christhompsontldr on 7/3/2024 in #❓┊help
How do I attach a livewire event to a Wizard's default action buttons?
The dispatch() and dispatchSelf() methods seem to do nothing. This code works, the ray() fires.
Wizard::make([
Step::make('Installer Details')
->afterValidation(function () { $this->updateModel(2); })
->schema([
Section::make('Installer Details')
->schema([
Actions::make([
Action::make('Print')->dispatchSelf('bandits'),
]),
...

#[On('bandits')]
public function bandits()
{
ray('here');
}
Wizard::make([
Step::make('Installer Details')
->afterValidation(function () { $this->updateModel(2); })
->schema([
Section::make('Installer Details')
->schema([
Actions::make([
Action::make('Print')->dispatchSelf('bandits'),
]),
...

#[On('bandits')]
public function bandits()
{
ray('here');
}
But this does nothing
->nextAction(fn (Action $action) => $action->dispatchSelf('bandits'))
->previousAction(fn (Action $action) => $action->dispatchSelf('bandits'))
->nextAction(fn (Action $action) => $action->dispatchSelf('bandits'))
->previousAction(fn (Action $action) => $action->dispatchSelf('bandits'))
1 replies
FFilament
Created by christhompsontldr on 7/1/2024 in #❓┊help
Temporary files are never moved
I am using Filament's Wizard for a multi-step form. On step 1, the model is created. On the last step, some files are uploaded. Those files make it to the livewire-tmp directory, but they are never moved after the form is submitted.
Step::make('File Attachments')
->schema(function () {
$fields = [];

foreach (Installer::$onboardingFiles as $field => $options) {
$fields[$field] =
Section::make([
FileUpload::make($field)
->label($options['title'])
->storeFileNamesIn($field . '_name')
->directory(fn () => 'installers/' . $this->installer->id . '/documents/' . $options['directory'])
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => $options['filename'] . '.' . $file->guessExtension())
->disk('s3')
->hidden(fn (Get $get): bool => $get($field . '_toggle')),
])
]);
}

return $fields;
}),
])
->submitAction(new HtmlString(Blade::render(<<<BLADE
<x-filament::button
type="submit"
size="sm"
wire:click="create"
>
Submit
</x-filament::button>
BLADE)))
]);
}

public function create(): void
{
$this->updateModel(5);
}
Step::make('File Attachments')
->schema(function () {
$fields = [];

foreach (Installer::$onboardingFiles as $field => $options) {
$fields[$field] =
Section::make([
FileUpload::make($field)
->label($options['title'])
->storeFileNamesIn($field . '_name')
->directory(fn () => 'installers/' . $this->installer->id . '/documents/' . $options['directory'])
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => $options['filename'] . '.' . $file->guessExtension())
->disk('s3')
->hidden(fn (Get $get): bool => $get($field . '_toggle')),
])
]);
}

return $fields;
}),
])
->submitAction(new HtmlString(Blade::render(<<<BLADE
<x-filament::button
type="submit"
size="sm"
wire:click="create"
>
Submit
</x-filament::button>
BLADE)))
]);
}

public function create(): void
{
$this->updateModel(5);
}
The files are not renamed or moved. I feel like I probably need to call a method to process the files, but the documentation doesn't mention it.
18 replies
FFilament
Created by christhompsontldr on 6/27/2024 in #❓┊help
Showing a relationship on one infolist, but not on the other.
I have an InstallerResource that has an edit page and an onboarding page.
public static function getRelations(): array
{
return [
MarketsRelationManager::make(),
];
}

public static function getPages(): array
{
return [
'index' => ListInstallers::route('/'),
'create' => CreateInstaller::route('/create'),
'edit' => EditInstaller::route('/{record}/edit'),
'logs' => InstallerLogs::route('/{record}/logs'),
'onboarding' => InstallerResource\Pages\ViewInstallerOnboarding::route('/{record}/onboarding'),
];
}
public static function getRelations(): array
{
return [
MarketsRelationManager::make(),
];
}

public static function getPages(): array
{
return [
'index' => ListInstallers::route('/'),
'create' => CreateInstaller::route('/create'),
'edit' => EditInstaller::route('/{record}/edit'),
'logs' => InstallerLogs::route('/{record}/logs'),
'onboarding' => InstallerResource\Pages\ViewInstallerOnboarding::route('/{record}/onboarding'),
];
}
The problem is, that configuring getRelations() here, puts the Markets relationship on both the onboarding page and on the edit page. I only want it on the edit page. How do I exclude that relationship from the onboarding page?
4 replies