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

Rules error in blade component #98

Open
evaleries opened this issue Jan 10, 2022 · 2 comments
Open

Rules error in blade component #98

evaleries opened this issue Jan 10, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@evaleries
Copy link

evaleries commented Jan 10, 2022

Describe the bug
Basically if we want to implement client-side validation we can do like Aire::open()->rules('key value of rules') or via blade component like <x-aire::form :rules="$rules"/>. Unfortunately, it didn't work as expected when I use blade component. I got an error Cannot unpack array with string keys.

My solutions are:

  1. Use {{Aire::open()->rules($rules)}}
  2. If we wanna use the blade component, make sure that we wrap the $rules with an array bracket ([$rules]). e.g: <x-aire::form :rules="[$rules]" />

My $rules variable:

$rules = [
     'full_name' => 'required|string'
];

Have you published the Aire config file?
No

Have you added custom Aire views?
No

What version does this affect?

  • Laravel Version: 8.77.1
  • Aire Version: 2.4

To Reproduce
Steps to reproduce the behavior:

  1. Create a blade view. Let's name it as form.blade.php.
  2. Edit form.blade.php with content below:
<x-aire::form :rules="$rules">
    <x-aire::input name="full_name" />
</x-aire::form>
  1. Create a new route in web.php. Route::view('/test', 'form');
  2. Visit /test/ and see the error.

Expected behavior
I expect the same result as I use Aire::form()->rules($rules) and <x-aire::form :rules="$rules"/>.

Additional context
OOC. How do I manually trigger the client-side validation? Like Aire.validate(). I tried the client-side validation but it didn't work.

Thank you for this package. I ❤️ it.

@evaleries evaleries added the bug Something isn't working label Jan 10, 2022
@inxilpro
Copy link
Contributor

Can you provide a copy of the code that you use to define the $rules variable? Are you sure you're passing an array?

@evaleries
Copy link
Author

evaleries commented Jan 14, 2022

Yes, I'm sure.

Here's my blade example:

@php
$rules = [
    'name' => 'required',
    'phone' => 'numeric'
];
@endphp

<x-aire::form :rules="$rules">
     <x-aire::input name="name" label="Name" />
     <x-aire::number name="phone" label="Phone" />
     <x-aire::submit label="Submit"/>
</x-aire::form>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants