Skip to content

Commit

Permalink
fix: ErrorMessage can not be displayed in two expression field (#2278)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Brown <asbrown002@gmail.com>
  • Loading branch information
alanlong9278 and a-b-r-o-w-n authored Mar 17, 2020
1 parent abb576e commit 6c39add
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ interface TwoSettingFieldsProps extends FieldProps<MicrosoftInputDialog> {
}
export const TwoSettingFields: React.FC<TwoSettingFieldsProps> = props => {
const { fields, formData, idSchema, getSchema, onChange, errorSchema } = props;
const errs: (JSX.Element | string | undefined)[] = [];
const [errorMessage, setErrorMessage] = useState<JSX.Element | string | undefined>();

const onValidate = (err?: JSX.Element | string) => {
setErrorMessage(err);
const onValidate = (index: number, err?: JSX.Element | string | undefined) => {
errs[index] = err;
setErrorMessage(errs.find(err => err || null));
};

return (
Expand All @@ -40,7 +42,9 @@ export const TwoSettingFields: React.FC<TwoSettingFieldsProps> = props => {
formContext={props.formContext}
rawErrors={errorSchema[settingField.name] && errorSchema[settingField.name].__errors}
hiddenErrMessage={true}
onValidate={onValidate}
onValidate={errMsg => {
onValidate(index, errMsg);
}}
/>
</div>
))}
Expand Down

0 comments on commit 6c39add

Please sign in to comment.