-
Notifications
You must be signed in to change notification settings - Fork 81
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
Clearing server-side validation errors upon submit #1407
Conversation
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.
Looks good, there's just a small thing. See below.
cadasta/organization/forms.py
Outdated
@@ -135,6 +135,11 @@ def clean_name(self): | |||
if slugify(name, allow_unicode=True) in invalid_names: | |||
raise forms.ValidationError( | |||
_("Organization name cannot be “Add” or “New”.")) | |||
|
|||
if Organization.objects.filter(name=name).exists(): |
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 think it's better to set the default unique error message for this field instead of adding a custom validation for this.
You can add this to the __init__
method:
self.fields['name'].error_messages['unique'] = _(
"Organization with this name already exists.")
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 for this @oliverroick. I've reworked it based on your recommendation so take another look and let me know if there is anything else I should change.
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.
Looks good!
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 changes look good and it works as advertised. 👍
Change text Add script to remove error block on submit if form not valid Removed alert Changed form_submit_once to form_submit
Proposed changes in this pull request
When should this PR be merged
Risks
Follow-up actions
Checklist (for reviewing)
General
migration
label if a new migration is added.Functionality
Code
Tests
Security
Documentation