F
Filament12mo ago
jeph

Validation didn't work

It's a simple ->gt() validation but I can't seem to make it work.. I can't figure out why. Please help. thanks.
Fieldset::make('Domain Length')
->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->hintIcon('heroicon-o-information-circle','Length excluding the extension.')
->numeric()
->gt('min')
->live(),
])->columnSpan(2),
Fieldset::make('Domain Length')
->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->hintIcon('heroicon-o-information-circle','Length excluding the extension.')
->numeric()
->gt('min')
->live(),
])->columnSpan(2),
I also tried custome rules but it still wont work.
TextInput::make('max')
->hintIcon('heroicon-o-information-circle','Length excluding the extension.')
->numeric()
->rules([
function () {
return function (GET $get, $value, Closure $fail) {
if ($value > $get('min') {
$fail('The :attribute is invalid.');
}
};
},
])
->live(),
TextInput::make('max')
->hintIcon('heroicon-o-information-circle','Length excluding the extension.')
->numeric()
->rules([
function () {
return function (GET $get, $value, Closure $fail) {
if ($value > $get('min') {
$fail('The :attribute is invalid.');
}
};
},
])
->live(),
5 Replies
Ngannv
Ngannv12mo ago
if you used custom view you need call validate method public function submit(): void { //Custom view needd call this method $this->form->validate();

$input = $this->data; ..... }
jeph
jephOP12mo ago
thanks a lot for the response @Ngannv ! My code is formatted like this:
public function form(Form $form): Form
{
return $form

->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->numeric()
->gt('min')
->live(),
]);
}

public function submit()
{
$query = Domain::query();
...

return $query;
}


public function table(Table $table): Table
{
return $table
->query($this->submit())
->columns([
...
]);
}

public function form(Form $form): Form
{
return $form

->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->numeric()
->gt('min')
->live(),
]);
}

public function submit()
{
$query = Domain::query();
...

return $query;
}


public function table(Table $table): Table
{
return $table
->query($this->submit())
->columns([
...
]);
}

Can you suggest where should I put the ->validate()? it would make error when I put
return $form->validate()
return $form->validate()
or
->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->numeric()
->gt('min')
->live(),
])->validate();
->schema([
TextInput::make('min')
->numeric()
->live(),
TextInput::make('max')
->numeric()
->gt('min')
->live(),
])->validate();
as well as
return $query->validate();
return $query->validate();
but the way, the form here is not used to save something to the server. i just used it to make a bit of complex query to the table. Hello @Ngannv ! Maybe you have some idea.
public function submit(): void
{
$this->form->validate();

$query = Domain::query();
...

return $query;
}
public function submit(): void
{
$this->form->validate();

$query = Domain::query();
...

return $query;
}
is not working. while
public function submit(): void
{
$this->validate();

$query = Domain::query();
...

return $query;
}
public function submit(): void
{
$this->validate();

$query = Domain::query();
...

return $query;
}
validation works with error message when the condition is false (max is less than min). but if the condition true (max is greater than min), it would throw an error: Typed property App\Livewire\Domaintable::$table must not be accessed before initialization
Ngannv
Ngannv12mo ago
This is my concept Php Filament CustomPage https://vhelper.pro/share/Zvt639wM4 And View: <x-filament-panels::page> <x-filament-panels::form autocomplete="off" wire:submit="submit"> {{ $this->form }} </x-filament-panels::form> </x-filament-panels::page>
Form validate with custom page
Our feature-rich tool offers quick text entry, saving, and link generation, making it the perfect alternative to pastebin for effortless sharing with others
Ngannv
Ngannv12mo ago
No description
jeph
jephOP12mo ago
Thank you so much for your time @Ngannv ! I really can't make that code work. Maybe there's something wrong with my code formatting. Is it okey to combine form and table in one component? maybe this is the one causing the problem. Here's the simplified version of my code: https://vhelper.pro/share/pGX641H2L
Form validate with custom page
Our feature-rich tool offers quick text entry, saving, and link generation, making it the perfect alternative to pastebin for effortless sharing with others
Want results from more Discord servers?
Add your server