fix: form submission when country is not requried (#1099)

When country is not required to submit, the displayValue check
will always return true. This fixes it by only check it if it's
needed through the config `SHOW_CONFIGURABLE_EDX_FIELDS`

This issue might has been discoverd at edx.org becuase edx.org
requires the Country to be filled when creating an account,
however this is not the case for Open edX by default, hence the
issue reported below

Ref: openedx/wg-build-test-release/issues/318
This commit is contained in:
Ghassan Maslamani
2023-11-13 18:14:34 +01:00
committed by Adolfo R. Brandes
parent 60e2119116
commit db4eeac266

View File

@@ -1,4 +1,4 @@
import { snakeCaseObject } from '@edx/frontend-platform';
import { getConfig, snakeCaseObject } from '@edx/frontend-platform';
import { LETTER_REGEX, NUMBER_REGEX } from '../../data/constants';
import messages from '../messages';
@@ -44,11 +44,12 @@ export const isFormValid = (
}
});
if (!configurableFormFields?.country?.displayValue) {
fieldErrors.country = formatMessage(messages['empty.country.field.error']);
isValid = false;
if (getConfig().SHOW_CONFIGURABLE_EDX_FIELDS) {
if (!configurableFormFields?.country?.displayValue) {
fieldErrors.country = formatMessage(messages['empty.country.field.error']);
isValid = false;
}
}
Object.keys(fieldDescriptions).forEach(key => {
if (key === 'country' && !configurableFormFields.country.displayValue) {
fieldErrors[key] = formatMessage(messages['empty.country.field.error']);