Skip to content
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

Publisher field and society field cannot have the same answer #2281

Closed
7 changes: 7 additions & 0 deletions doajtest/testbook/new_application_form/publishers_form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ tests:
- step: Click the X next to it
results:
- It disappears
- step: Enter the same value in Publisher's Name and Publisher's Country
- step: Click Next
results:
- "You see the error message: The value of this field and the Publisher's Country field must be different."
- step: Repeat previous step checking if the validator is case insensitive (e.g. "Publisher's name" and "publisher's Name")
results:
- The error message is still displayed
- step: Repeat steps X to X for the Publisher's Name, Country, Society name, Country
- step: Delete the values from Society name and country, click Next
results:
Expand Down
12 changes: 9 additions & 3 deletions portality/forms/application_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ class FieldDefinitions:
"label": "Publisher’s name",
"input": "text",
"validate": [
{"required": {"message": "Enter the name of the journal’s publisher"}}
{"required": {"message": "Enter the name of the journal’s publisher"}},
{"different_to": {"field": "institution_name", "message": "This field must be different than 'Society or institution’s name'"}} # ~~^-> DifferetTo:FormValidator~~
],
"widgets": [
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~
Expand Down Expand Up @@ -563,6 +564,10 @@ class FieldDefinitions:
]
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis overwrites the widgets on the base field, so it needs to include the autocomplete and any other widgets that you also want active on the admin form.

"validate": [
{"different_to": {"field": "publisher_name",
"message": "This field must be different than 'Publisher’s name'"}} # ~~^-> DifferetTo:FormValidator~~
],
"widgets": [
"trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~
{"autocomplete": {"type" : "journal", "field": "bibjson.institution.name.exact"}},
Expand Down Expand Up @@ -1758,7 +1763,7 @@ class FieldDefinitions:
"input": "taglist",
"validate": [
{"is_issn_list": {"message": "This is not a valid ISSN"}}, # ~~^-> IsISSN:FormValidator~~
{"different_to": {"field": "continued_by"}}, # ~~^-> DifferetTo:FormValidator~~
{"different_to": {"field": "continued_by", "message": "The ISSN provided in both fields must be different. Please make sure to enter the ISSN of an older journal for the first field and the ISSN of a newer journal for the second field. They cannot be the same."}}, # ~~^-> DifferetTo:FormValidator~~
{
"not_if" : {
"fields" : [{"field" : "discontinued_date"}],
Expand All @@ -1781,7 +1786,7 @@ class FieldDefinitions:
"input": "taglist",
"validate": [
{"is_issn_list": {"message": "This is not a valid ISSN"}}, # ~~^-> IsISSN:FormValidator~~
{"different_to": {"field": "continues"}}, # ~~^-> DifferetTo:FormValidator~~
{"different_to": {"field": "continues", "message": "The ISSN provided in both fields must be different. Please make sure to enter the ISSN of an older journal for the first field and the ISSN of a newer journal for the second field. They cannot be the same."}}, # ~~^-> DifferetTo:FormValidator~~
{
"not_if": {
"fields": [{"field": "discontinued_date"}],
Expand Down Expand Up @@ -2801,6 +2806,7 @@ class DifferentToBuilder:
@staticmethod
def render(settings, html_attrs):
html_attrs["data-parsley-different-to"] = settings.get("field")
html_attrs["data-parsley-different-to-message"] = "<p><small>" + settings.get("message") + "</small></p>"

@staticmethod
def wtforms(field, settings):
Expand Down
4 changes: 2 additions & 2 deletions portality/static/js/application_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ window.Parsley.addValidator("optionalIf", {
});

window.Parsley.addValidator("differentTo", {
validateString : function(value, requirement) {
return (!value || ($("[name = " + requirement + "]")).val() !== value);
validateString : function(value, requirement, message) {
return (!value || ($("[name = " + requirement + "]")).val().toLowerCase() !== value.toLowerCase());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function takes the argument message but doesn't use it, is that required by the Parsley interface or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's overlook. Sorry!

},
messages: {
en: 'Value of this field and %s field must be different'
Expand Down