Issue #801: Added regex pattern to Name & UniqueName fields and custo…#822
Issue #801: Added regex pattern to Name & UniqueName fields and custo…#822ahungerford-unicon wants to merge 3 commits intomainfrom
Conversation
…m error checking for those fields
| // # Disabled pattern validation here; now handled on handleCreateOrEdit | ||
| // if (field.pattern && createParams[field.name] && !new RegExp(field.pattern).test(createParams[field.name])) { | ||
| // setCreateError(`The following fields have invalid values:\n > ${field.patternErr}`); | ||
| // } |
There was a problem hiding this comment.
Left this in but commented as I originally had this checking as the field was edited, but wasn't really satisfied with the result since it would replace any onSave reported errors as soon as you started to correct one of them. I believe we could get inline checking done without this if we updated the Dialog to an actual form, since that is how the pattern attribute usually works, but my quick tests with it caused other issues to crop up for Dialog that didn't make it worth it.
bjagg
left a comment
There was a problem hiding this comment.
Hey @ahungerford-unicon — took a look at this while reviewing open PRs. The implementation approach is clean (validating on submit, patternErr for custom messages, whiteSpace: pre-line for multi-line errors). Nice call avoiding the inline validation — that's the right tradeoff for a dialog.
One concern with the regex ^[A-Za-z][A-Za-z0-9_]*$: it would be too restrictive for the existing UniqueName conventions in the MDR data. Looking at the seed data in V1.1__metadata_repository_init.sql, UniqueName values routinely use dots as path separators:
Common.Contact.Address.informationSourceIdAssessment.shortNameachievement.achievementType
There are hundreds of entries following this dotted-path pattern. Even after #810 removes spaces, dots would still be needed for UniqueName. The current regex would prevent creating or editing any entries that follow the existing convention.
A few thoughts:
-
Name vs UniqueName may need different regexes. Name fields (
firstName,Identifier) tend to be simple identifiers, but UniqueName fields (Common.Contact.Address.informationSourceId) use dotted paths. Something like^[A-Za-z][A-Za-z0-9_.]*$for UniqueName might work better. -
Worth aligning with #811 (API validation) before finalizing the regex here — the frontend and backend should enforce the same rules.
-
Value Names (the last field updated in
CreateOptFields.tsx) may have different conventions than entity/attribute names — worth checking if those need dots too.
Happy to help dig into the data further if useful.
…m error checking for those fields
Edit: Changed it to a Draft as this requires #810 to be completed first.