F
Filament4mo ago
Willy

Testing Repeater

I'm testing a repeater, and for some reason I get a distinct validation error.
it('should show an error when the email is duplicated in the form', function () {
Repeater::fake();

actingAs(User::factory()->create());

$team = Team::factory()->create();
Filament::setTenant($team);

livewire(Members::class)
->fillForm([
'emailAddresses' => [
['email' => '[email protected]'],
['email' => '[email protected]'],
],
])
->call('create')
->assertHasFormErrors([
'emailAddresses.0.email' => 'distinct',
'emailAddresses.1.email' => 'distinct',
]);
});
it('should show an error when the email is duplicated in the form', function () {
Repeater::fake();

actingAs(User::factory()->create());

$team = Team::factory()->create();
Filament::setTenant($team);

livewire(Members::class)
->fillForm([
'emailAddresses' => [
['email' => '[email protected]'],
['email' => '[email protected]'],
],
])
->call('create')
->assertHasFormErrors([
'emailAddresses.0.email' => 'distinct',
'emailAddresses.1.email' => 'distinct',
]);
});
Repeater::make('emailAddresses')
->label(__('filament/clusters/settings/pages/team/members.form.repeater.label'))
->minItems(1)
->maxItems(5)
->defaultItems(1)
->deletable(fn($state) => is_array($state) && count($state) > 1)
->reorderable(false)
->addActionLabel(__('filament/clusters/settings/pages/team/members.form.repeater.addActionLabel'))
->simple(
TextInput::make('email')
->required()
->placeholder('[email protected]')
->email()
->distinct()
->unique(Invitation::class),
),
Repeater::make('emailAddresses')
->label(__('filament/clusters/settings/pages/team/members.form.repeater.label'))
->minItems(1)
->maxItems(5)
->defaultItems(1)
->deletable(fn($state) => is_array($state) && count($state) > 1)
->reorderable(false)
->addActionLabel(__('filament/clusters/settings/pages/team/members.form.repeater.addActionLabel'))
->simple(
TextInput::make('email')
->required()
->placeholder('[email protected]')
->email()
->distinct()
->unique(Invitation::class),
),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server