Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep nested data validated wrong - nested rule values overwrite root rule values #120

Closed
faustbrian opened this issue Aug 5, 2019 · 1 comment

Comments

@faustbrian
Copy link
Contributor

commented Aug 5, 2019

Livewire at the moment seems to handle deep nested data and validation in a wrong way. The given example results in such wrong way of handling it.

// View
<input type="text" wire:model="items.{{ $loop->index }}.api_key" />
<input type="text" wire:model="items.{{ $loop->index }}.api_secret" />
<input type="text" wire:model="items.{{ $loop->index }}.from" />
<input type="text" wire:model="items.{{ $loop->index }}.to" />

// Component
public function persist(): void
{
    $data = this->validate([
        'items'              => ['required', 'array'],
        'items.*'            => ['array'],
        'items.*.api_key'    => ['required', 'string'],
        'items.*.api_secret' => ['required', 'string'],
        'items.*.from'       => ['required', 'numeric'],
        'items.*.to'         => ['required', 'numeric'],
    ]);
    
    $this->getModel()->settings()->set('notifications.nexmo', $data['items']);
}

This line changes the items property from being an associative array with nested items to simply become 'items' => 'items.*.to'.

I tested this with various different nested rules and it seems to always overwrite the root rule with the last nested rule. What I mean by this is that items is the root rule and items.*.to is the last nested rule and that last nested rule overwrites items with its value.

@faustbrian faustbrian changed the title Deep nested data handled wrong Deep nested data validated wrong - nested rule values overwrite root rule values Aug 5, 2019

@calebporzio

This comment has been minimized.

Copy link
Owner

commented Aug 6, 2019

You're right, that line was clobbering the validation input.

I fixed this, and the fix will be available in the next release.

@calebporzio calebporzio closed this Aug 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.