From bddce5a206348d18f302318bfd61d2231e42a70d Mon Sep 17 00:00:00 2001 From: Aga Date: Fri, 4 Aug 2023 09:53:58 +0100 Subject: [PATCH 1/5] make differentTo validator case insensitive --- portality/static/js/application_form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portality/static/js/application_form.js b/portality/static/js/application_form.js index 178aef09c4..3944845669 100644 --- a/portality/static/js/application_form.js +++ b/portality/static/js/application_form.js @@ -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()); }, messages: { en: 'Value of this field and %s field must be different' From 05f67c761ae0d05f368803a058bbaa2f3046d5ce Mon Sep 17 00:00:00 2001 From: Aga Date: Fri, 4 Aug 2023 09:54:32 +0100 Subject: [PATCH 2/5] add DifferentTo validator to Publishers name and Institution name fields, make sure message is passed correctly --- portality/forms/application_forms.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index 0065b765fc..b088a9786c 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -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~~ @@ -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"}}, @@ -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"] = "

" + settings.get("message") + "

" @staticmethod def wtforms(field, settings): From 5fce92245d3cf2aaa5de59e8918feeddb17fd15e Mon Sep 17 00:00:00 2001 From: Aga Date: Fri, 4 Aug 2023 10:00:16 +0100 Subject: [PATCH 3/5] add functional test --- doajtest/testbook/new_application_form/publishers_form.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doajtest/testbook/new_application_form/publishers_form.yml b/doajtest/testbook/new_application_form/publishers_form.yml index 07f1c2e40a..72b4de2316 100644 --- a/doajtest/testbook/new_application_form/publishers_form.yml +++ b/doajtest/testbook/new_application_form/publishers_form.yml @@ -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: From 69cd7cf930dcfc86273f9632ebb912c4db6554e4 Mon Sep 17 00:00:00 2001 From: Aga Date: Mon, 16 Oct 2023 11:45:40 +0100 Subject: [PATCH 4/5] add error message to the continuations validator --- portality/forms/application_forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index a1df8b78c7..4eef1e45a8 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -1763,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"}], @@ -1786,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"}], From c388be7ccf977a075b1086a7b2810c95bb401e4b Mon Sep 17 00:00:00 2001 From: Aga Date: Mon, 6 Nov 2023 14:16:33 +0000 Subject: [PATCH 5/5] merge and change message --- portality/forms/application_forms.py | 86 +++++++++++++--------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/portality/forms/application_forms.py b/portality/forms/application_forms.py index 634839db75..ebe21abebe 100644 --- a/portality/forms/application_forms.py +++ b/portality/forms/application_forms.py @@ -417,8 +417,8 @@ class FieldDefinitions: "input": "taglist", "help": { "long_help": ["Choose upto 6 keywords that describe the subject matter of the journal. " - "Keywords must be in English.", "Use single words or short phrases (2 to 3 words) " - "that describe the journal's main topic.", "Do not add acronyms, abbreviations or descriptive sentences.", + "Keywords must be in English.", "Use single words or short phrases (2 to 3 words) " + "that describe the journal's main topic.", "Do not add acronyms, abbreviations or descriptive sentences.", "Note that the keywords may be edited by DOAJ editorial staff." ], }, "validate": [ @@ -477,7 +477,7 @@ class FieldDefinitions: "input": "text", "validate": [ {"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~~ + {"different_to": {"field": "institution_name", "message": "Publisher and Society/Institution names cannot be the same."}} # ~~^-> DifferetTo:FormValidator~~ ], "widgets": [ "trim_whitespace", # ~~^-> TrimWhitespace:FormWidget~~ @@ -564,6 +564,11 @@ class FieldDefinitions: {"autocomplete": {"type" : "journal", "field": "bibjson.institution.name.exact"}}, # ~~^-> Autocomplete:FormWidget~~ "full_contents" # ~~^->FullContents:FormWidget~~ ], + "validate": [ + {"different_to": {"field": "publisher_name", + "message": "Publisher and Society/Institution names cannot be the same."}} + # ~~^-> DifferetTo:FormValidator~~ + ], "contexts": { "admin": { "widgets": [ @@ -590,19 +595,6 @@ class FieldDefinitions: ] } } - "click_to_copy", # ~~^-> ClickToCopy:FormWidget~~ - ] - } - }, - "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"}}, - "full_contents" # ~~^->FullContents:FormWidget~~ - ] } # ~~->$ InstitutionCountry:FormField~~ @@ -751,7 +743,7 @@ class FieldDefinitions: "field": "license_display", "value": "y", "message": "Enter the URL for any recent article that displays or embeds a license" - } + } }, "is_url" # ~~^->IsURL:FormValidator~~ ], @@ -859,7 +851,7 @@ class FieldDefinitions: "field": "review_process", "value": "other", "message": "Enter the name of another type of peer review" - } + } } ], "widgets" : [ @@ -898,8 +890,8 @@ class FieldDefinitions: "datatype": "integer", "help": { "long_help": ["Please enter the year that the journal started to publish all content as true open access, according to DOAJ's definition.", - "For journals that have flipped to open access, enter the year that the journal flipped, not the original launch date of the journal.", - "For journals that have made digitised backfiles freely available, enter the year that the journal started publishing as a fully open access title, not the date of the earliest free content."] + "For journals that have flipped to open access, enter the year that the journal flipped, not the original launch date of the journal.", + "For journals that have made digitised backfiles freely available, enter the year that the journal started publishing as a fully open access title, not the date of the earliest free content."] }, "validate": [ {"required": {"message": "Enter the Year (YYYY)."}}, @@ -951,7 +943,7 @@ class FieldDefinitions: "field": "plagiarism_detection", "value": "y", "message": "Enter the URL for the journal’s plagiarism policy page" - } + } }, "is_url" # ~~^->IsURL:FormValidator~~ ], @@ -1198,14 +1190,14 @@ class FieldDefinitions: "help": { "short_help": "Link to the journal’s waiver information.", "doaj_criteria": "You must provide a URL", - "placeholder": "https://www.my-journal.com/about#waiver" + "placeholder": "https://www.my-journal.com/about#waiver" }, "validate": [ {"required_if": { "field": "has_waiver", "value": "y", "message": "Enter the URL for the journal’s waiver information page" - } + } }, "is_url" # ~~^->IsURL:FormValidator~~ ], @@ -1253,7 +1245,7 @@ class FieldDefinitions: "field": "has_other_charges", "value": "y", "message": "Enter the URL for the journal’s fees information page" - } + } }, "is_url" # ~~^->IsURL:FormValidator~~ ], @@ -1312,7 +1304,7 @@ class FieldDefinitions: "field": "preservation_service", "value": "national_library", "message": "Enter the name(s) of the national library or libraries where the journal is archived" - } + } } ], "asynchronous_warning": [ @@ -1338,7 +1330,7 @@ class FieldDefinitions: "field": "preservation_service", "value": "other", "message": "Enter the name of another archiving policy" - } + } } ], "asynchronous_warning": [ @@ -1437,7 +1429,7 @@ class FieldDefinitions: "field": "deposit_policy", "value": "other", "message": "Enter the name of another repository policy" - } + } } ], "asynchronous_warning": [ @@ -1524,8 +1516,8 @@ class FieldDefinitions: ], "help": { "long_help": ["A persistent article identifier (PID) is used to find the article no matter where it is " - "located. The most common type of PID is the digital object identifier (DOI). ", - "Read more about PIDs."], + "located. The most common type of PID is the digital object identifier (DOI). ", + "Read more about PIDs."], }, "validate": [ {"required": {"message": "Select at least one option"}} @@ -1543,7 +1535,7 @@ class FieldDefinitions: "field": "persistent_identifiers", "value": "other", "message": "Enter the name of another type of identifier" - } + } } ], "asynchronous_warning": [ @@ -1566,7 +1558,7 @@ class FieldDefinitions: "default" : "", "help": { "long_help": ["An ORCID (Open Researcher and Contributor) iD is an alphanumeric code to uniquely identify " - "authors."], + "authors."], }, "contexts" : { "public" : { @@ -1657,7 +1649,7 @@ class FieldDefinitions: "input": "textarea", "help": { "long_help": ["The selected reason for rejection, and any additional information you include, " - "are sent to the journal contact with the rejection email."] + "are sent to the journal contact with the rejection email."] }, "validate": [ {"required_if": {"field": "quick_reject", "value": "other"}} @@ -1707,7 +1699,7 @@ class FieldDefinitions: "help" : { "render_error_box": False, "short_help" : "Set the status to 'In Progress' to signal to the applicant that you have started your review." - "Set the status to 'Completed' to alert the Editor that you have completed your review.", + "Set the status to 'Completed' to alert the Editor that you have completed your review.", "update_requests_diff": False } }, @@ -1715,7 +1707,7 @@ class FieldDefinitions: "help" : { "render_error_box" : False, "short_help" : "Revert the status to 'In Progress' to signal to the Associate Editor that further work is needed." - "Set the status to 'Ready' to alert the Managing Editor that you have completed your review.", + "Set the status to 'Ready' to alert the Managing Editor that you have completed your review.", "update_requests_diff": False } } @@ -1844,18 +1836,18 @@ class FieldDefinitions: "validate": [ {"required_if" : { "field" : "application_status", - "value" : [ - constants.APPLICATION_STATUS_READY, - constants.APPLICATION_STATUS_COMPLETED, - constants.APPLICATION_STATUS_ACCEPTED - ], - "message" : "This field is required when setting the Application Status to {y}, {z} or {a}".format( - y=constants.APPLICATION_STATUS_READY, - z=constants.APPLICATION_STATUS_COMPLETED, - a=constants.APPLICATION_STATUS_ACCEPTED - ) - } - } + "value" : [ + constants.APPLICATION_STATUS_READY, + constants.APPLICATION_STATUS_COMPLETED, + constants.APPLICATION_STATUS_ACCEPTED + ], + "message" : "This field is required when setting the Application Status to {y}, {z} or {a}".format( + y=constants.APPLICATION_STATUS_READY, + z=constants.APPLICATION_STATUS_COMPLETED, + a=constants.APPLICATION_STATUS_ACCEPTED + ) + } + } ], "widgets": [ "subject_tree" @@ -3107,7 +3099,7 @@ class MultiCheckboxBuilder(WTFormsBuilder): @staticmethod def match(field): return field.get("input") == "checkbox" and \ - (len(field.get("options", [])) > 0 or field.get("options_fn") is not None) + (len(field.get("options", [])) > 0 or field.get("options_fn") is not None) @staticmethod def wtform(formulaic_context, field, wtfargs):