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

More meaningful regex error messages #2640

Merged
merged 7 commits into from
May 1, 2024

Conversation

hutattedonmyarm
Copy link
Contributor

@hutattedonmyarm hutattedonmyarm commented Nov 15, 2023

References

Description

Adds field-specific error messages for regex validation in the form of error.validation.pattern.schema_element_qualifier.
If no error message for a specific field has been added to the i18n files, the old error message will be used.

Instructions for Reviewers

  • Add a regex validation for a field, e.g. dc.title in the submission configuration
  • Enter a value which does not pass the regex validation
  • No change should be visible now compared to before
  • Then add the corresponding message key to the i18n files, e.g. error.validation.pattern.dc_title with custom error message
  • Restart your frontend
  • Now the custom error message should be visible

Checklist

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using yarn lint
  • My PR doesn't introduce circular dependencies (verified via yarn check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@tdonohue tdonohue added component: submission error handling How errors are handled from REST API 1 APPROVAL pull request only requires a single approval to merge labels Nov 15, 2023
@tdonohue tdonohue added the bug label Feb 1, 2024
@tdonohue tdonohue self-requested a review February 1, 2024 15:58
Copy link

github-actions bot commented Mar 8, 2024

Hi @hutattedonmyarm,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@tdonohue
Copy link
Member

@hutattedonmyarm : Apologies for the long delay on revisiting this work. Could you rebase this on latest main so that it's easier to test? I'd like to get this tested for possible inclusion in 8.0

@kanasznagyzoltan
Copy link

kanasznagyzoltan commented Apr 25, 2024

I have tested this improvement and it has worked for me.

I have modified the dc.title field in the default form (traditionalpageone) of the submission.xml:

            <row>
                <field>
                    <dc-schema>dc</dc-schema>
                    <dc-element>title</dc-element>
                    <dc-qualifier></dc-qualifier>
                    <repeatable>false</repeatable>
                    <label>Title Regex</label>
                    <input-type>onebox</input-type>
                    <hint>Enter the main title of the item.</hint>
                    <required>You must enter a main title for this item.</required>
                    **<regex>/[a-z]+/i</regex>**
                </field>
            </row>

I have added an extra translation key to the English translation file of the dspace-angular frontend:
"error.validation.pattern.dc_title": "The title for the given pattern is not valid... this error message comes from translation file and related to the dc.title field!"

If I put an invalid input to the field I got my custom translation back:
2

If I remove my custom translation key I got the default translation corresponding to the acceptance regular expression:
1

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

👍 Thanks @hutattedonmyarm ! I also had a chance to give this a test (based on @kanasznagyzoltan 's example) and it's working well. So, I'll merge this into 8.0 and 7.x immediately.

That said, I'm going to add the needs documentation as I think we should mention in the documentation that these regex messages are now translatable. If you have the chance to add a note to the Submission Docs (next to the docs for regex), that may be the best place. If you don't have access you can also add basic notes here & I'll get them copied over.

@tdonohue tdonohue added the needs documentation PR is missing documentation. All new features and config changes require documentation. label May 1, 2024
@tdonohue tdonohue added this to the 8.0 milestone May 1, 2024
@tdonohue tdonohue merged commit 0607878 into DSpace:main May 1, 2024
13 checks passed
@hutattedonmyarm
Copy link
Contributor Author

@tdonohue I don't have an account for the wiki. I'd suggest to add a note to the "regex" section. I've left the beginning as is and added instructions

regex: When specified, this field will be validated against the Regular Expression, and only successfully validating values will be saved. An example is commented out in the default "Author" field. If the validation fails, the following error message will be shown by default: "This input is restricted by the current pattern: {{ pattern }}.". This can be customized, by adding an entry to the internalization files with the key error.validation.pattern.schema_element_qualifier and the schema, element and qualifier of the field. For example: "error.validation.pattern.dc_identifier": "The identifier can only consist of numbers". For instructions on how to add custom entries see: Customize UI labels using Internationalization (i18n) files

@tdonohue
Copy link
Member

tdonohue commented May 2, 2024

Thanks @hutattedonmyarm ! I've copied those docs into the 7.x and 8.x documentation for the Submission User Interface. I'll remove the needs documentation flag now.

@tdonohue tdonohue removed the needs documentation PR is missing documentation. All new features and config changes require documentation. label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 APPROVAL pull request only requires a single approval to merge bug component: submission error handling How errors are handled from REST API
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

DSpace 7: more meaningful regex message
4 participants