#Validate on suffixAction

4 messages · Page 1 of 1 (latest)

timber torrent
#

I've got a form that is mostly visual, and only a couple of editing points, and doesn't have a general submit.

I thought I could be clever where I wanted a field to be editable in that view, by having a suffix Action acting as a save button for that field.

                    ->columnSpan(1)
                    ->live()
                    ->suffixAction(
                        Action::make('saveTelephone')
                            ->icon('heroicon-m-cloud-arrow-up')
                            ->tooltip('Save Telephone')
                            ->action(function ($record, $get) {

                                $record->rf_referee_telephone = $get('rf_referee_telephone');
                                $record->save();

                                Notification::make()
                                    ->title('Telephone Saved')
                                    ->success()
                                    ->send();
                            })
                            ->visible(function ($record, $get) : bool {

                                return $record->rf_referee_telephone !== $get('rf_referee_telephone');

                            })

                    ),```

Works fine, but there is no validation run. Is there a command I can have within the action to run the field validation prior to the save?

Cheers
faint trenchBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

toxic grove
timber torrent
#

Thanks for this. I tried this, but it didn't work initially. I thought it may be something to do with the form being in a modal, and sure enough the prefix on the wire:model is not 'data'.

So: $livewire->validateOnly('mountedTableActionsData.0.rf_referee_telephone'); works...but can I rely on that always targetting the right element?