How can I validate this?

Hi I want to validate first if the Product line and Client have chosen when i click to add button in the project.
8 Replies
DrByte
DrByte12mo ago
Add required() or rules([]) to the field, and then also add afterStateUpdated() to make it check immediately when the field is changed. Maybe also set the debounce(). ie:
->required()
->debounce(400)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
// @phpstan-ignore-next-line
$livewire->validateOnly($component->getStatePath());
})
->required()
->debounce(400)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
// @phpstan-ignore-next-line
$livewire->validateOnly($component->getStatePath());
})
trisharvey13
trisharvey13OP12mo ago
Gist
My COde
My COde. GitHub Gist: instantly share code, notes, and snippets.
DrByte
DrByte12mo ago
On your product_line_id Select component you have both required() so add afterStateUpdated as well. Same with your client Select component.
trisharvey13
trisharvey13OP12mo ago
i can still click the + icon even if i did not choose product and client it should promt that project and client is required
DrByte
DrByte12mo ago
Oh. I wasn't looking at the + icon.
DrByte
DrByte12mo ago
I'm not super-familiar with that Component ... but this appears to be the code that controls it: https://github.com/filamentphp/filament/blob/7713dc2703c29ccd824cc04a48b3b95c6081898e/packages/forms/src/Components/Select.php#L264-L333
GitHub
filament/packages/forms/src/Components/Select.php at 7713dc2703c29c...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
DrByte
DrByte12mo ago
Perhaps you might be able to use createOptionAction() to change the action based on whether those other fields have a value?
trisharvey13
trisharvey13OP12mo ago
will check thank you
Want results from more Discord servers?
Add your server