From a24da74189a27e7ba3fc5337b61919a7fd76ff33 Mon Sep 17 00:00:00 2001 From: Darin McLain Date: Fri, 13 Jan 2023 07:49:52 -0500 Subject: [PATCH] Added a condition with the isNew flag in the handleChange event for the Name input field (#25) --- src/components/flags/FlagForm.tsx | 5 +++-- src/components/segments/SegmentForm.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/flags/FlagForm.tsx b/src/components/flags/FlagForm.tsx index dbff644..a243e8b 100644 --- a/src/components/flags/FlagForm.tsx +++ b/src/components/flags/FlagForm.tsx @@ -95,8 +95,9 @@ export default function FlagForm(props: FlagFormProps) { // check if the name and key are currently in sync // we do this so we don't override a custom key value if ( - formik.values.key === '' || - formik.values.key === stringAsKey(previousName) + isNew && + (formik.values.key === '' || + formik.values.key === stringAsKey(previousName)) ) { formik.setFieldValue( 'key', diff --git a/src/components/segments/SegmentForm.tsx b/src/components/segments/SegmentForm.tsx index 287bf09..2564562 100644 --- a/src/components/segments/SegmentForm.tsx +++ b/src/components/segments/SegmentForm.tsx @@ -99,8 +99,9 @@ export default function SegmentForm(props: SegmentFormProps) { // check if the name and key are currently in sync // we do this so we don't override a custom key value if ( - formik.values.key === '' || - formik.values.key === stringAsKey(previousName) + isNew && + (formik.values.key === '' || + formik.values.key === stringAsKey(previousName)) ) { formik.setFieldValue('key', stringAsKey(e.target.value)); }