-
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
fix: feature test with validation #7548
fix: feature test with validation #7548
Conversation
I was sure that we added an error reset to the |
We can rest |
This makes sense in theory, but what if people have more than one form on a page and send everything to the same controller? Each form goes into a separate class where it is validated, and errors are returned at the same time. If we reset the errors every time the |
@michalsn How do we send two forms at the same time? |
The |
I believe this solution is the best for now. I merge. |
@kenjis With a little JavaScript, it's possible, but I explained it poorly since I didn't mean the JS example. What I meant is one form with fields like:
which will be sent to one endpoint and then handled via separate classes. |
@michalsn What do you mean by via separate classes? If it means one Validation object validates the form1 data and another Validation object does the form2 data, Maybe separate classes but they use a shared Validation object? |
Yes, exactly this. |
@michalsn Maybe I do not quite understand, but it seems to me that your example looks like bad architecture. + Wrong decision to make a shared validator instance. |
@michalsn I too think such usage is too tricky and kind of misuse. |
Like having more than one form on a single page or handling the validation of each form in a separate class? The context is important because each form is also used separately (alone) in different places of the application. So it makes code reusable and easy to work with.
Using a shared validation instance has its advantages, like the ability to use form helper functions (related to displaying error messages). Personally, I see no issues with using a shared instance as long as you know what you're doing.
I'm not sure if this behavior was intended, but I can see cases when bending the rules can work out for us. If I had to implement something as I described now, with CI4, I would probably take advantage of this "feature". The idea was to show that other developers can use the validation class in very different ways and in my opinion, we should leave this class as flexible as possible. Forcing to use |
Description
See https://forum.codeigniter.com/showthread.php?tid=87844
Feature testing shares the Validation object between requests.
So the validation result is incorrect after a failed validation.
Checklist: