mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Removes nested ternary in CredentialField validate param by moving logic out to a function and making it a little more readable.
This commit is contained in:
@@ -76,19 +76,20 @@ function CredentialField({ credentialType, fieldOptions, i18n }) {
|
|||||||
const { values: formikValues } = useFormikContext();
|
const { values: formikValues } = useFormikContext();
|
||||||
const requiredFields = credentialType?.inputs?.required || [];
|
const requiredFields = credentialType?.inputs?.required || [];
|
||||||
const isRequired = requiredFields.includes(fieldOptions.id);
|
const isRequired = requiredFields.includes(fieldOptions.id);
|
||||||
|
const validateField = () => {
|
||||||
|
if (isRequired && !formikValues?.passwordPrompts[fieldOptions.id]) {
|
||||||
|
const validationMsg = fieldOptions.ask_at_runtime
|
||||||
|
? i18n._(
|
||||||
|
t`Provide a value for this field or select the Prompt on launch option.`
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
return required(validationMsg, i18n);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
const [subFormField, meta, helpers] = useField({
|
const [subFormField, meta, helpers] = useField({
|
||||||
name: `inputs.${fieldOptions.id}`,
|
name: `inputs.${fieldOptions.id}`,
|
||||||
validate:
|
validate: validateField(),
|
||||||
isRequired && !formikValues?.passwordPrompts[fieldOptions.id]
|
|
||||||
? required(
|
|
||||||
fieldOptions.ask_at_runtime
|
|
||||||
? i18n._(
|
|
||||||
t`Provide a value for this field or select the Prompt on launch option.`
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
i18n
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
});
|
});
|
||||||
const isValid = !(meta.touched && meta.error);
|
const isValid = !(meta.touched && meta.error);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user