-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: add Form helpers for Validation Errors #6384
Conversation
927dc43
to
d92376b
Compare
It makes me a little uneasy, but I scoured the docs and we don't actually have the current behavior documented anywhere. This has also caused lots of confusion, and I for one have never taken advantage of the session errors as an actual feature. I do like the new implementation. My opinion: proceed with the PR and let's get someone else to give an opinion on the potential breaking impact. |
@paulbalandan or @iRedds? |
Yes, this behavior is undocumented. So if we think it is not an official feature, this PR is NOT a breaking change, I've asked about the behavior in the forum: |
Unserialize. |
Some might think that the |
This is outside the scope of this PR, but I would like to show my vision of dealing with validation errors. I want to say right away that it is based on Laraway.
|
I agree with the shared error bag across the application, just like the |
Indeed, but it is outside the scope of this PR. |
We can add the fallback to get Validation from Services and return the errors. |
I did. Now we can use exactly the same view file whether we are displaying Form directly or redirecting to Form. |
cef6fb7
to
7ea834b
Compare
Added |
Big dreams! ErrorBag sounds great but for the issue at hand I like the proposed changes. The double serialization is a good point - I would like to see that fixed in the same release as this PR, before people start actually using this new feature. |
Okay, probably nobody or very few people use this session errors, so I will fix it in this PR tomorrow. |
Removed |
50c4ccd
to
03d250a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kenjis! Looks good to me. Anyone else have remaining comments? Should we start a project card for ErrorBag?
03d250a
to
18b52bf
Compare
Rebased and added three commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice User Guide write-up! I think this is ready, just added some thoughts for discussion.
@@ -506,6 +500,8 @@ public function setRuleGroup(string $group) | |||
|
|||
/** | |||
* Returns the rendered HTML of the errors as defined in $template. | |||
* | |||
* You can also use validation_list_errors() in Form helper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we deprecate this function and require the use of the helper? It's always been rather weird that our Validation class has a dependency on View.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is certainly possible to deprecate this method since it duplicates functionality.
If so, what would we do with the error view files and templates setting?
See https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html#configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like your functions still use those components. What else would you do with them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question is: If we decouple View from the Validation class, where do we put the validation error templates and its configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counterquestion. Why are error patterns needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's error pattern?
Maybe it will be changed to ErrorBag.
/github/workspace/user_guide_src/source/incoming/routing.rst:458: WARNING: undefined label: spark-routes
13e93a5
to
8b2a669
Compare
Co-authored-by: MGatner <[email protected]>
0abfa49
to
f322d5d
Compare
GET/POST data and the Validation Errors are used together when a validation error occurs. Therefore, it is not bad that withInput() also saves the validation errors.
f322d5d
to
a12b231
Compare
I've changed my mind, and removed |
I've merged to pass the "Test User Guide / Check User Guide syntax".
|
Description
Fixes #6380
Supersedes #6381
About the bug:
Validation::run()
must reset the validation errors in the session.Changes:
validation_errors()
to get the validation errors arrayvalidation_list_errors()
to get the rendered HTML of the validation errorsvalidation_show_error()
to get the rendered HTML of the single validation errorHow to Use
Controller:
View:
or
Checklist: