-
Notifications
You must be signed in to change notification settings - Fork 395
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
fields: keep entries order in errors list #258
Conversation
wtforms/fields/core.py
Outdated
|
||
chain = itertools.chain(self.validators, extra_validators) | ||
self._run_validation_chain(form, chain) | ||
|
||
return len(self.errors) == 0 | ||
return not error_occured |
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.
This ignores errors from _run_validation_chain
(hence the failing test). What about return all(e is None for e in self.errors)
?
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.
Hmmm. Yes, it will work, I guess.
Should I add the changes to this pull request? I'm still bad with pull requests, so I'm not sure it's even possible in technical meaning :)
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.
Yeah, you can add more changes, it's as simple as pushing to the-tosh:master
👍
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.
Done. Thanks!
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.
Sorry about this, but my initial comment had a wrong suggestion :( The line should be return all(e is None for e in self.errors)
.
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.
The funniest thing here, that I've been already about typing all
... and then I just copypaste line from your message :) Well, fixed.
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.
I'd like to point out here that adding None
to a list is actually adding something, but in this case its of NoneType
. The else
block in like 925 is doing more work for no good reason.
Thanks for trying to contribute! Having said that this PR isn't refining what it appears to be doing. Adding As of now I'm going to be closing the PR. If you happen to find anything that you'd like to help out with dont hesitate to submit another PR. |
To clarify, I think what we're saying is that the issue can be solved by rendering the errors for the subfields individually. Perhaps you're using a template macro and it can be adjusted to understand nested fields. |
@whb07 Looking at from multidict import MultiDict
from wtforms import FieldList, validators, Form, TextField
class TestForm(Form):
test_field = FieldList(TextField("Test", [validators.required()]))
data = MultiDict([('test_field-{}'.format(i), value) for i, value in enumerate(['a', ''])])
form = TestForm(data)
assert not form.validate()
print(form.errors)
# This would imply list item 0 has an error:
# {'test_field': [['This field is required.']]}
for f in form.test_field: print(f.errors)
# []
# ['This field is required.'] @davidism It's possible to work around it, like you say. But the problem then becomes that My use case is AJAX form validation. I respond with |
Okay this newest message shows me what you're actually trying to say. I do think that this issue of the FieldList not keeping track of the data passed to it is something that should be worked on. Having said that, the current PR as it stands is not doing that. So clearly when you pass in the data such as If thats your goal, I'd like to help out. Open a new PR with possible changes and tests verifying what you are talking about. I'll be happy to take a look at it as I've also run into this issue. |
No description provided.