F
Filament6mo ago
Aminne

How i can display the error message before submit

Forms\Components\Select::make('from_id')
->relationship(name: 'from',
modifyQueryUsing: fn (Builder $query, Get $get) => $query->where('id', '!=', $get('to_id')))
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->holder->name}")
->preload()
->searchable()
->required()
->live(onBlur: true)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\Select $component) {
$livewire->validateOnly($component->getStatePath());
})
->rules([
fn () => function (string $attribute, $value, Closure $fail) {
$wallet = Wallet::find($value);
if(intval($wallet->balance) === 0) {
$fail('The :attribute wallet is empty.');
}
},
]),
Forms\Components\Select::make('from_id')
->relationship(name: 'from',
modifyQueryUsing: fn (Builder $query, Get $get) => $query->where('id', '!=', $get('to_id')))
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->holder->name}")
->preload()
->searchable()
->required()
->live(onBlur: true)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\Select $component) {
$livewire->validateOnly($component->getStatePath());
})
->rules([
fn () => function (string $attribute, $value, Closure $fail) {
$wallet = Wallet::find($value);
if(intval($wallet->balance) === 0) {
$fail('The :attribute wallet is empty.');
}
},
]),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server