display the validation error message the user input w/ burnettk (#386)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
jasquat 2023-07-12 02:10:48 -04:00 committed by GitHub
parent be41619c60
commit d0d2d20ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -76,9 +76,6 @@ export default function BaseInputTemplate<
} else if (schema && schema.title) {
labelToUse = schema.title;
}
if (required) {
labelToUse = `${labelToUse}*`;
}
let helperText = null;
if (uiSchema && uiSchema['ui:help']) {

View File

@ -7,6 +7,7 @@ interface typeaheadArgs {
onChange: any;
options: any;
value: any;
schema?: any;
uiSchema?: any;
disabled?: boolean;
readonly?: boolean;
@ -20,6 +21,7 @@ export default function TypeaheadWidget({
onChange,
options: { category, itemFormat },
value,
schema,
uiSchema,
disabled,
readonly,
@ -45,8 +47,15 @@ export default function TypeaheadWidget({
}
}
let labelToUse = label;
if (uiSchema && uiSchema['ui:title']) {
labelToUse = uiSchema['ui:title'];
} else if (schema && schema.title) {
labelToUse = schema.title;
}
if (!category) {
errorMessageForField = `category is not set in the ui:options for this field: ${label}`;
errorMessageForField = `category is not set in the ui:options for this field: ${labelToUse}`;
invalid = true;
}
@ -106,7 +115,13 @@ export default function TypeaheadWidget({
if (!invalid && rawErrors && rawErrors.length > 0) {
invalid = true;
[errorMessageForField] = rawErrors;
if ('validationErrorMessage' in schema) {
errorMessageForField = (schema as any).validationErrorMessage;
} else {
errorMessageForField = `${(labelToUse || '').replace(/\*$/, '')} ${
rawErrors[0]
}`;
}
}
return (