diff --git a/awx/ui_next/src/screens/Inventory/shared/InventorySourceForm.jsx b/awx/ui_next/src/screens/Inventory/shared/InventorySourceForm.jsx index 5ad8b8ff8e..dfeb11ee1a 100644 --- a/awx/ui_next/src/screens/Inventory/shared/InventorySourceForm.jsx +++ b/awx/ui_next/src/screens/Inventory/shared/InventorySourceForm.jsx @@ -47,6 +47,7 @@ const InventorySourceFormFields = ({ source, sourceOptions, i18n }) => { values, initialValues, resetForm, + setFieldTouched, setFieldValue, } = useFormikContext(); const [sourceField, sourceMeta] = useField({ @@ -92,6 +93,7 @@ const InventorySourceFormFields = ({ source, sourceOptions, i18n }) => { }; Object.keys(defaults).forEach(label => { setFieldValue(label, defaults[label]); + setFieldTouched(label, false); }); } }; @@ -255,7 +257,7 @@ const InventorySourceForm = ({ overwrite: source?.overwrite || false, overwrite_vars: source?.overwrite_vars || false, source: source?.source || '', - source_path: source?.source_path === '' ? '/ (project root)' : '', + source_path: source?.source_path || '', source_project: source?.summary_fields?.source_project || null, source_script: source?.summary_fields?.source_script || null, source_vars: source?.source_vars || '---\n', diff --git a/awx/ui_next/src/screens/Inventory/shared/InventorySourceSubForms/SCMSubForm.jsx b/awx/ui_next/src/screens/Inventory/shared/InventorySourceSubForms/SCMSubForm.jsx index b0f846833c..9e53b05948 100644 --- a/awx/ui_next/src/screens/Inventory/shared/InventorySourceSubForms/SCMSubForm.jsx +++ b/awx/ui_next/src/screens/Inventory/shared/InventorySourceSubForms/SCMSubForm.jsx @@ -21,7 +21,7 @@ import { } from './SharedFields'; const SCMSubForm = ({ autoPopulateProject, i18n }) => { - const { setFieldValue } = useFormikContext(); + const { setFieldValue, setFieldTouched } = useFormikContext(); const [credentialField] = useField('credential'); const [projectField, projectMeta, projectHelpers] = useField({ name: 'source_project', @@ -47,16 +47,20 @@ const SCMSubForm = ({ autoPopulateProject, i18n }) => { useEffect(() => { if (projectMeta.initialValue) { fetchSourcePath(projectMeta.initialValue.id); - } + if (sourcePathField.value === '') { + sourcePathHelpers.setValue('/ (project root)'); + } + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [fetchSourcePath, projectMeta.initialValue]); const handleProjectUpdate = useCallback( value => { - setFieldValue('source_path', ''); setFieldValue('source_project', value); + setFieldValue('source_path', ''); + setFieldTouched('source_path', false); fetchSourcePath(value.id); }, - [fetchSourcePath, setFieldValue] + [fetchSourcePath, setFieldValue, setFieldTouched] ); const handleCredentialUpdate = useCallback(