diff --git a/src/libs/ErrorUtils.js b/src/libs/ErrorUtils.js index fdeae7809f58..95bbad5f5409 100644 --- a/src/libs/ErrorUtils.js +++ b/src/libs/ErrorUtils.js @@ -88,6 +88,26 @@ function getLatestErrorField(onyxData, fieldName) { .value(); } +/** + * @param {Object} onyxData + * @param {Object} onyxData.errorFields + * @param {String} fieldName + * @returns {Object} + */ +function getEarliestErrorField(onyxData, fieldName) { + const errorsForField = lodashGet(onyxData, ['errorFields', fieldName], {}); + + if (_.isEmpty(errorsForField)) { + return {}; + } + return _.chain(errorsForField) + .keys() + .sortBy() + .map((key) => ({[key]: errorsForField[key]})) + .first() + .value(); +} + /** * Method used to generate error message for given inputID * @param {Object} errors - An object containing current errors in the form @@ -112,4 +132,4 @@ function addErrorMessage(errors, inputID, message) { } } -export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getLatestErrorMessage, getLatestErrorField, addErrorMessage}; +export {getAuthenticateErrorMessage, getMicroSecondOnyxError, getLatestErrorMessage, getLatestErrorField, getEarliestErrorField, addErrorMessage}; diff --git a/src/pages/settings/Profile/Contacts/ValidateCodeForm/BaseValidateCodeForm.js b/src/pages/settings/Profile/Contacts/ValidateCodeForm/BaseValidateCodeForm.js index 5b1aa87cea80..a24b7036bd48 100644 --- a/src/pages/settings/Profile/Contacts/ValidateCodeForm/BaseValidateCodeForm.js +++ b/src/pages/settings/Profile/Contacts/ValidateCodeForm/BaseValidateCodeForm.js @@ -165,7 +165,7 @@ function BaseValidateCodeForm(props) { User.clearContactMethodErrors(props.contactMethod, 'validateLogin')} >