From cafd9ce4ba4e4a11125909e63ac5e90efdacab4a Mon Sep 17 00:00:00 2001 From: Mohammed Saud Date: Thu, 7 Jul 2022 19:36:48 +0530 Subject: [PATCH] run validation with updated resource values --- src/shared/components/formik-fields/ResourceLimitField.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/components/formik-fields/ResourceLimitField.tsx b/src/shared/components/formik-fields/ResourceLimitField.tsx index 7815a4af7..dbce4a9f9 100644 --- a/src/shared/components/formik-fields/ResourceLimitField.tsx +++ b/src/shared/components/formik-fields/ResourceLimitField.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { FormGroup } from '@patternfly/react-core'; import { useField, useFormikContext, FormikValues } from 'formik'; +import { set } from 'lodash-es'; import { RequestSizeInput } from '../../utils'; import { ResourceLimitFieldProps } from './field-types'; import { getFieldId } from './field-utils'; @@ -14,7 +15,7 @@ const ResourceLimitField: React.FC = ({ }) => { const [field, { touched, error }] = useField(props.name); const [fieldUnit] = useField(unitName); - const { setFieldValue, setFieldTouched } = useFormikContext(); + const { setFieldValue, setFieldTouched, values, validateForm } = useFormikContext(); const fieldId = getFieldId(props.name, 'resource-limit'); const isValid = !(touched && error); const errorMessage = !isValid ? error : ''; @@ -31,6 +32,8 @@ const ResourceLimitField: React.FC = ({ { + // run validation manually so that formik uses the latest value + validateForm(set(values, props.name, val.value)); setFieldValue(props.name, val.value); setFieldTouched(props.name, true); setFieldValue(unitName, val.unit);