Skip to content

Commit

Permalink
fix(Form): fix runtime error when error is object
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Feb 22, 2019
1 parent 5dd6810 commit 7f7af04
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const [FormFieldTag, themeField] = createThemeTag(name, {
}),
});

const [ControlLabelTag, themeLabel] = createThemeTag(`${name}Label`, ({ COLORS, SIZES }: *) => ({
const [FormLabel, themeLabel] = createThemeTag(`${name}Label`, ({ COLORS, SIZES }: *) => ({
root: props => ({
fontSize: SIZES.OVERLINE_1,
lineHeight: SIZES.OVERLINE_1_LH,
Expand Down Expand Up @@ -85,23 +85,27 @@ const FormField = ({
...rest
}: FormFieldProps) => {
const hasError = formUtils.hasError(meta);
const error = formUtils.getError(meta);
let error: any = formUtils.getError(meta);

const hasLabel = !!label;

if (typeof error === 'object') {
error = Object.keys(error).map(key => error[key]);
}

return (
<FormFieldTag { ...rest } tagName="div">
<FormFieldDirectionTag modifiers={ rest } tagName="div">
<If condition={ hasLabel }>
<ControlLabelTag modifiers={ rest } tagName="div">
<FormLabel modifiers={ rest } tagName="div">
{ label }
</ControlLabelTag>
</FormLabel>
</If>
{ children }
</FormFieldDirectionTag>
<If condition={ hasError && !hideErrorLabel }>
<ControlErrorWrapperTag modifiers={ rest } tagName="div">
<ControlErrorTag modifiers={ rest } role="alert" tagName="span">{ error }</ControlErrorTag>
<ControlErrorTag modifiers={ rest } role="alert" tagName="span">{ error.toString() }</ControlErrorTag>
</ControlErrorWrapperTag>
</If>
</FormFieldTag>
Expand All @@ -114,5 +118,5 @@ FormField.defaultProps = {
direction: 'column',
};

export { FormField, theme, ControlLabelTag, ControlErrorTag };
export { FormField, theme, FormLabel, ControlErrorTag };

0 comments on commit 7f7af04

Please sign in to comment.