-
Notifications
You must be signed in to change notification settings - Fork 296
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
Errors not showing in child form fields #78
Comments
Because
Add this function to So things like |
How do you set up validation rules? It works fine when you set rules with real name, for example: $rules = [
'title' => 'required'
]; |
That is pretty limiting when it comes to different child forms having the same field name. And just generally feels wrong considering it both goes against how Laravel handles the naming and just in general you wouldnt refer to a field in a form array as just that field name would you? |
Also this just breaks Laravel validation of child forms as the validation checks child fields via dot notation, so theres no way a field on a child form can not have a dot notation name. I'm curious what setup this is working for you with? |
Yes, agree it's limiting. Definitely needs to be fixed. Validation checks by the field name, so for example if $rules = [
'invoice[title]' => 'required'
]; In package i do not use dot notation for that kind of stuff, because it's more understandable for all developers with Dot notation is just a convention used by Laravel, but in the background it translates to the |
Oh I didnt know validation keys could be set like I just changed my keys to that format and it is at least working for the wrapper attributes when there is an error but doesnt show the error message below the field (as the error message is trying to grab I feel the commit about fixing child form error displaying ironically broke child form error displaying :P |
in the views needs to just go back to
for this to work for me |
Yeah someone else reported that it's not working with regular names, like i put in example. This needs fix. Will do it soon, thanks. |
I'm going to be updating all the views so that it does work for me so I'll submit a PR with the view changes. |
That would be great, thank you. |
You said naming fields like |
Yes, i just tested it out again. Something like this: <?php
$rules = [
'invoice[title]' => 'required'
];
class MainForm extends Form {
public function buildForm()
{
$this->add('invoice', 'form', [
'class' => 'App\Forms\InvoiceForm'
]);
}
}
class InvoiceForm extends Form {
public function buildForm()
{
$this->add('title');
}
} |
hmmm I cant use keys like that. Validation just doesnt get touched. i.e. required rule has errors even when value provided. And you're using purely Laravel validation in your domain? |
Yes, you're right, i tested only to see if there are any errors, but not if passes. Will look into it, thanks. |
Do you even use this package yourself anymore? haha I'm making changes so that it solves the issue for me, I'll put in another PR and you can look at it. |
I didn't have need for nested forms, done only simple apps with simple forms. Great, thanks. |
Closing this as new PR makes it redundant |
It looks like the real_name is getting set to the individual field's name, when in the HTML the name includes the name of the child form too because its in array format.
Testing out which version of this breaks it as it seems to have broken since I composer updated it from being on an old version.
Update:
Yeah the issue is with
which was brought in a commit about "fixing errors in child forms" (ironically lol)
In my case, I have a child form under 'invoice' with a text field 'title'. This is keyed in laravel's error bag as 'invoice.title'. The 'real_name' of the field is 'title' and the
$name
equals 'invoice[title]'.Is this working for you?
Basically the field needs a dot notation name including the names of its parent form(s) to get the error from
$errors
.The text was updated successfully, but these errors were encountered: