Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiForm] Added invalidCallout prop to allow conditional rendering of error callout #3585

Merged
merged 12 commits into from
Jun 11, 2020
2 changes: 1 addition & 1 deletion src-docs/src/views/form_validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default () => {

return (
<Fragment>
<EuiForm isInvalid={showErrors} error={errors}>
<EuiForm isInvalid={showErrors} error={errors} showCallout={true}>
<EuiFormRow label="Validation only" isInvalid={showErrors}>
<EuiFieldText name="first" isInvalid={showErrors} />
</EuiFormRow>
Expand Down
6 changes: 4 additions & 2 deletions src/components/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type EuiFormProps = CommonProps &
*/
component?: 'form' | 'div';
error?: ReactNode | ReactNode[];
showCallout?: boolean;
cchaos marked this conversation as resolved.
Show resolved Hide resolved
};

export const EuiForm: FunctionComponent<EuiFormProps> = ({
Expand All @@ -47,6 +48,7 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
isInvalid,
error,
component = 'div',
showCallout,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
...rest
}) => {
const classes = classNames('euiForm', className);
Expand All @@ -68,11 +70,11 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({

let optionalErrorAlert;

if (isInvalid) {
if (isInvalid && showCallout) {
optionalErrorAlert = (
<EuiI18n
token="euiForm.addressFormErrors"
default="Please address the errors in your form.">
default="Please address the errors highlighted below.">
cchaos marked this conversation as resolved.
Show resolved Hide resolved
{(addressFormErrors: string) => (
<EuiCallOut
className="euiForm__errors"
Expand Down