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
8 changes: 7 additions & 1 deletion portality/forms/application_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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 @@ -505,6 +506,10 @@ class FieldDefinitions:
"a society or other type of institution, enter that here."],
"placeholder": "Type or select the society or institution’s name"
},
"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 @@ -2743,6 +2748,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