F
Filament4mo ago
Abi

Cannot get custom Validation Message for Select Component to work

I have the following Select component with the required validation.
Select::make('existing_kids')
->label('Select existing family members who will attending this event')
->required(function (Get $get) {
return count($get('add_new_kids')) === 0;
})
->validationMessages([
'required' => 'You will need to select at least one family member to attend this event. If you don\'t have any existing family members, please add a new family member below.',
])
->multiple()
Select::make('existing_kids')
->label('Select existing family members who will attending this event')
->required(function (Get $get) {
return count($get('add_new_kids')) === 0;
})
->validationMessages([
'required' => 'You will need to select at least one family member to attend this event. If you don\'t have any existing family members, please add a new family member below.',
])
->multiple()
It does validate correctly, but the custom validation doesn't show. Here is what it shows. I have the same issue with other components also not showing custom validation messages.
No description
Solution:
$this->form->getState() will validate the form
Jump to solution
9 Replies
Abi
AbiOP4mo ago
Am I missing anything? I tried to use native() as well and doesn't work with that as well.
LeandroFerreira
LeandroFerreira4mo ago
are you using a statePath? provide more info or the whole code..
Dennis Koch
Dennis Koch4mo ago
Just tested with the demo, so it's not a bug in Filament:
No description
Abi
AbiOP4mo ago
ok, so, I am using Filament Forms as standalone and not within the Admin Panel. I have setup all the form elements inside the form(Form $form) method with the necessary validations for each form element. On form submission, when I call the $this->validate(), it doesn't seem to use the custom message I have setup for each element, but does the normal validation message configured on the lang file. I don't have a statePath setup
LeandroFerreira
LeandroFerreira4mo ago
$this->form->getState() actually
Dennis Koch
Dennis Koch4mo ago
Share your code. There shouldn't be a $this->validate()
Solution
LeandroFerreira
LeandroFerreira4mo ago
$this->form->getState() will validate the form
Abi
AbiOP4mo ago
Yes, I followed the documentation. how do I go about validating the form on form submission? if I don't use $this->validate() it doesn't seem to validate. ah ok, let me check that ok, now that works, thank you very much.
Want results from more Discord servers?
Add your server