Skip to content

Commit

Permalink
Refactor validation messages for improved formatting and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Nov 25, 2024
1 parent 450311d commit 5ad8f00
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Common/UI/Components/Forms/Validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ export default class Validation {
if (content && field.validation) {
if (field.validation.minLength) {
if (content.trim().length < field.validation?.minLength) {
return `${field.title || name} cannot be less than ${field.validation.minLength
} characters.`;
return `${field.title || name} cannot be less than ${
field.validation.minLength
} characters.`;
}
}

if (field.validation.maxLength) {
if (content.trim().length > field.validation?.maxLength) {
return `${field.title || name} cannot be more than ${field.validation.maxLength
} characters.`;
return `${field.title || name} cannot be more than ${
field.validation.maxLength
} characters.`;
}
}

Expand Down Expand Up @@ -87,15 +89,17 @@ export default class Validation {

if (field.validation.maxValue) {
if (content > field.validation?.maxValue) {
return `${field.title || name} should not be more than ${field.validation?.maxValue
}.`;
return `${field.title || name} should not be more than ${
field.validation?.maxValue
}.`;
}
}

if (field.validation.minValue) {
if (content < field.validation?.minValue) {
return `${field.title || name} should not be less than ${field.validation?.minValue
}.`;
return `${field.title || name} should not be less than ${
field.validation?.minValue
}.`;
}
}
}
Expand Down Expand Up @@ -135,10 +139,11 @@ export default class Validation {
field.validation?.toMatchField &&
entity[field.validation?.toMatchField] &&
(entity[field.validation?.toMatchField] as string).toString().trim() !==
content.trim()
content.trim()
) {
return `${field.title} should match ${field.validation?.toMatchField as string
}`;
return `${field.title} should match ${
field.validation?.toMatchField as string
}`;
}
return null;
}
Expand Down Expand Up @@ -246,13 +251,12 @@ export default class Validation {

const name: string = field.name;


// is this field visible? If not visible, skip validation.

if (field.showIf) {
const isVisible: boolean = field?.showIf(args.values);

if(!isVisible) {
if (!isVisible) {
continue;
}
}
Expand Down

0 comments on commit 5ad8f00

Please sign in to comment.