Skip to content

Commit

Permalink
run validation with updated resource values
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Saud committed Jul 18, 2022
1 parent da444ef commit cafd9ce
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/shared/components/formik-fields/ResourceLimitField.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +15,7 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
}) => {
const [field, { touched, error }] = useField(props.name);
const [fieldUnit] = useField(unitName);
const { setFieldValue, setFieldTouched } = useFormikContext<FormikValues>();
const { setFieldValue, setFieldTouched, values, validateForm } = useFormikContext<FormikValues>();
const fieldId = getFieldId(props.name, 'resource-limit');
const isValid = !(touched && error);
const errorMessage = !isValid ? error : '';
Expand All @@ -31,6 +32,8 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
<RequestSizeInput
{...props}
onChange={(val) => {
// 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);
Expand Down

0 comments on commit cafd9ce

Please sign in to comment.