Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion frontends/mdr-frontend/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface DialogField {
accept?: string;
inputMode?: InputMode;
pattern?: string;
patternErr?: string;
}

export interface DialogItem {
Expand Down Expand Up @@ -92,6 +93,10 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
nextParams.BaseDataModelId = null;
}
}
// # 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}`);
// }
Comment on lines +96 to +99
Copy link
Contributor Author

@ahungerford-unicon ahungerford-unicon Jan 30, 2026

Choose a reason for hiding this comment

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

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.

return nextParams;
});
};
Expand All @@ -111,6 +116,12 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
setCreateError(`Please complete all required fields: ${missingFields.join(", ")}`);
return;
}

const regexFields = fields.filter((f) => f.pattern && createParams[f.name] && !new RegExp(f.pattern).test(createParams[f.name]));
if (regexFields.length) {
setCreateError(`The following fields have invalid values:\n > ${regexFields.map(f => f.patternErr).join("\n > ")}`);
return;
}

setDisableSubmitForm(true);
if (isEditMode && itemToEdit) {
Expand Down Expand Up @@ -228,7 +239,7 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
{createError && (
<>
<br /><br />
<Text color="red" size="2" mb="3">
<Text color="red" size="2" mb="3" style={{ whiteSpace: "pre-line" }}>
{createError}
</Text>
</>
Expand Down Expand Up @@ -298,6 +309,7 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
onChange={(e) => handleFieldValueChange(field, e.target.value) }
inputMode={field.inputMode}
pattern={field.pattern}
title={field.patternErr ?? ""}
readOnly={field.readOnly || (isEditMode && field.name === "CreationDate")}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ export const entityCreateFields = (model: any): DialogField[] => {
hidden: true,
defaultValue: model?.Id,
},
{ name: "Name", type: "text" as const, label: "Name", required: true },
{
name: "Name",
type: "text" as const,
label: "Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Name must start with a letter and contain only letters, numbers, and underscores.",
},
{
name: "UniqueName",
type: "text" as const,
label: "Unique Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Unique Name must start with a letter and contain only letters, numbers, and underscores.",
},
{ name: "Description", type: "text" as const, label: "Description" },
{
Expand Down Expand Up @@ -90,12 +99,21 @@ export const attributeCreateFields = (model: any, valueSetId: string | number |
hidden: true,
defaultValue: valueSetId?.toString(),
},
{ name: "Name", type: "text" as const, label: "Name", required: true },
{
name: "Name",
type: "text" as const,
label: "Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Name must start with a letter and contain only letters, numbers, and underscores.",
},
{
name: "UniqueName",
type: "text" as const,
label: "Unique Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Unique Name must start with a letter and contain only letters, numbers, and underscores.",
},
{
name: "DataType",
Expand Down Expand Up @@ -173,7 +191,14 @@ export const valueSetCreateFields = (model: any): DialogField[] => {
hidden: true,
defaultValue: model?.Id,
},
{ name: "Name", type: "text" as const, label: "Name", required: true },
{
name: "Name",
type: "text" as const,
label: "Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Name must start with a letter and contain only letters, numbers, and underscores.",
},
{ name: "Description", type: "text" as const, label: "Description" },
{
name: "Use Considerations",
Expand Down Expand Up @@ -223,6 +248,8 @@ export const valueCreateFields = (model: any): DialogField[] => {
type: "text" as const,
label: "Value Name",
required: true,
pattern: "^[A-Za-z][A-Za-z0-9_]*$",
patternErr: "Value Name must start with a letter and contain only letters, numbers, and underscores.",
},
{ name: "Description", type: "text" as const, label: "Description" },
{
Expand Down