From 28a62ea774f82e8f1e90fad932209ef42e741ac3 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Wed, 23 Jun 2021 08:46:11 -0400 Subject: properly validates credential password fields --- .../src/components/FormField/PasswordInput.jsx | 12 ++++++++-- .../CredentialFormFields/CredentialField.jsx | 17 ++++++++++--- .../CredentialPlugins/CredentialPluginField.jsx | 28 +++++++++++++--------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/awx/ui_next/src/components/FormField/PasswordInput.jsx b/awx/ui_next/src/components/FormField/PasswordInput.jsx index 4747ef1319..0062ad4cb9 100644 --- a/awx/ui_next/src/components/FormField/PasswordInput.jsx +++ b/awx/ui_next/src/components/FormField/PasswordInput.jsx @@ -12,7 +12,15 @@ import { import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons'; function PasswordInput(props) { - const { autocomplete, id, name, validate, isRequired, isDisabled } = props; + const { + autocomplete, + id, + name, + validate, + isFieldGroupValid, + isRequired, + isDisabled, + } = props; const [inputType, setInputType] = useState('password'); const [field, meta] = useField({ name, validate }); @@ -44,7 +52,7 @@ function PasswordInput(props) { value={field.value === '$encrypted$' ? '' : field.value} isDisabled={isDisabled} isRequired={isRequired} - validated={isValid ? 'default' : 'error'} + validated={isValid || isFieldGroupValid ? 'default' : 'error'} type={inputType} onChange={(_, event) => { field.onChange(event); diff --git a/awx/ui_next/src/screens/Credential/shared/CredentialFormFields/CredentialField.jsx b/awx/ui_next/src/screens/Credential/shared/CredentialFormFields/CredentialField.jsx index d7c579e2f3..2633da056a 100644 --- a/awx/ui_next/src/screens/Credential/shared/CredentialFormFields/CredentialField.jsx +++ b/awx/ui_next/src/screens/Credential/shared/CredentialFormFields/CredentialField.jsx @@ -26,7 +26,12 @@ const FileUpload = styled(PFFileUpload)` flex-grow: 1; `; -function CredentialInput({ fieldOptions, credentialKind, ...rest }) { +function CredentialInput({ + fieldOptions, + isFieldGroupValid, + credentialKind, + ...rest +}) { const [fileName, setFileName] = useState(''); const [fileIsUploading, setFileIsUploading] = useState(false); const [subFormField, meta, helpers] = useField(`inputs.${fieldOptions.id}`); @@ -116,6 +121,7 @@ function CredentialInput({ fieldOptions, credentialKind, ...rest }) { <> {RevertReplaceButton} { @@ -235,7 +243,10 @@ function CredentialField({ credentialType, fieldOptions }) { isRequired={isRequired} validated={isValid ? 'default' : 'error'} > - + ); } diff --git a/awx/ui_next/src/screens/Credential/shared/CredentialPlugins/CredentialPluginField.jsx b/awx/ui_next/src/screens/Credential/shared/CredentialPlugins/CredentialPluginField.jsx index 952eeb214a..8b37f241d3 100644 --- a/awx/ui_next/src/screens/Credential/shared/CredentialPlugins/CredentialPluginField.jsx +++ b/awx/ui_next/src/screens/Credential/shared/CredentialPlugins/CredentialPluginField.jsx @@ -98,15 +98,23 @@ function CredentialPluginField(props) { const [, meta, helpers] = useField(`inputs.${fieldOptions.id}`); const [passwordPromptField] = useField(`passwordPrompts.${fieldOptions.id}`); - const invalidHelperTextToDisplay = meta.error && meta.touched && ( -
- {meta.error} -
- ); + let invalidHelperTextToDisplay; + + if (meta.error && meta.touched) { + invalidHelperTextToDisplay = ( +
+ {meta.error} +
+ ); + } + + if (fieldOptions.id === 'vault_password' && passwordPromptField.value) { + invalidHelperTextToDisplay = null; + } useEffect(() => { if (passwordPromptField.value) { @@ -119,8 +127,6 @@ function CredentialPluginField(props) { <> {fieldOptions.ask_at_runtime ? (