dspace-angular
dspace-angular copied to clipboard
More meaningful regex error messages
References
- Fixes DSpace/DSpace#9178
- Backported to 7.x in #2641
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.titlein 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_titlewith custom error message - Restart your frontend
- Now the custom error message should be visible
Checklist
- [x] 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.
- [x] My PR passes ESLint validation using
yarn lint - [x] My PR doesn't introduce circular dependencies (verified via
yarn check-circ-deps) - [x] My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
- [x] My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
- [x] 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. - [x] If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
- [x] If my PR fixes an issue ticket, I've linked them together.
Hi @hutattedonmyarm, Conflicts have been detected against the base branch. Please resolve these conflicts as soon as you can. Thanks!
@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
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:
If I remove my custom translation key I got the default translation corresponding to the acceptance regular expression:
@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
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.