App icon indicating copy to clipboard operation
App copied to clipboard

[CFI] [$175] Expense creation - Show required-field validation error above the footer button

Open MelvinBot opened this issue 3 weeks ago • 28 comments

Problem

When a required expense field is outside the visible scroll area, clicking Save Expense can appear to do nothing. The field-level validation error is not visible near the footer, leaving the user without an obvious explanation of why saving is blocked.

The original report, Unable to create a new Expense from Reports > More > Create Expense, was closed after the thread clarified that the amount was missing from a manually completed expense. This issue tracks the separate validation-feedback UX improvement, not a failure to save a valid expense.

Example flow

  1. Go to Spend > Reports and open a report containing an expense.
  2. Choose More > Add Expense > Create Expense.
  3. Select Scan and upload a receipt.
  4. Select tags/category and expand Show more / More Details.
  5. Manually enter merchant and date, but leave amount empty.
  6. Scroll so the amount field is out of view, then click Save Expense.

Reported behavior: Saving is blocked by the missing amount, but its inline error is outside the viewport, making the button appear unresponsive.

Reported environment: Windows, Firefox; version 9.5.27-2. This follow-up has not been independently reproduced, and the improvement should not be assumed to be Firefox-specific.

Requested improvement

Display a visible validation summary immediately above the footer button when required fields prevent expense creation, including when the affected fields are out of view.

Suggested copy from the discussion: “Please enter the required fields.” with the standard error indicator.

  • Preserve the specific inline errors on the affected fields.
  • Keep invalid submissions blocked; do not bypass validation.
  • Clear the summary when the required-field errors are corrected.
  • Showing more coding options alone should not be treated as opting out of SmartScan; the example involves manually entering expense fields.

Acceptance criteria

  • Submitting with a missing required field outside the viewport shows an explanation above the footer button.
  • The error is also understandable when the affected field is visible.
  • Correcting all required fields clears the error and allows normal expense creation.

Slack thread: https://expensify.slack.com/archives/C049HHMV9SM/p1793658573409119

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @rlinoz

MelvinBot avatar Nov 06 '26 18:11 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @TaduJR (External)

melvin-bot[bot] avatar Nov 06 '26 18:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022118773025354391284

melvin-bot[bot] avatar Nov 06 '26 18:11 melvin-bot[bot]

Proposal

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:

const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
    error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');

const computeErrorMessage = (): string | undefined => {
    if (routeError) {
        return routeError;
    }
    if (isSuppressedInline(formError)) {
        return undefined;
    }
    ...
  1. When validation fails due to missing required fields, useConfirmationValidation sets formError = 'common.error.fieldRequired'.
  2. However, isSuppressedInline intentionally suppresses common.error.fieldRequired from computeErrorMessage() so that specific inline error messages on individual inputs are not duplicated verbatim in the footer.
  3. As a result, errorMessage evaluates to undefined, and ConfirmationFooterContent.tsx:205–214 renders nothing in its footer FormHelpMessage above the button.
  4. When the invalid field is scrolled off-screen, the user receives zero feedback when clicking "Save Expense".
  5. Furthermore, the automatic-clearing hook in useFormErrorManagement.ts:224–236 checks isAmountRequiredMissing, isDateRequiredMissing, and isMerchantRequiredMissing, but must ensure required manual merchants are strictly evaluated so correcting Amount does not prematurely clear the summary while Merchant remains blank.

What changes do you think we should make in order to solve the problem?

  1. Add new localized summary copy: In src/languages/en.ts:

    iou: {
        error: {
            enterRequiredFields: 'Please enter the required fields.',
        },
    }
    

    In src/languages/es.ts:

    iou: {
        error: {
            enterRequiredFields: 'Por favor, completa los campos requeridos.',
        },
    }
    
  2. Return the summary error for required-field failures in useFormErrorManagement.ts: In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts: Distinguish between missing required fields and invalid non-empty inputs (such as overlength merchants or invalid custom amounts).

    • Keep internal validation keys and specific inline errors on fields unchanged.
    • For formError === 'common.error.fieldRequired', return the summary translation translate('iou.error.enterRequiredFields') in the existing footer error message:
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        if (formError === 'common.error.fieldRequired') {
            return translate('iou.error.enterRequiredFields');
        }
        if (isSuppressedInline(formError)) {
            return undefined;
        }
        return formError ? translate(formError) : undefined;
    };
    
  3. Split Expenses handling: Ensure the live required-field summary error is shown immediately for split expense validation without unnecessary debounce delay, while preserving debounce handling for other dynamic validation errors and retaining route-error priority and submission blocking.

  4. Auto-clearing hook alignment: In useFormErrorManagement.ts:224–236, ensure manual required merchants (isMerchantRequiredMissing) and unset amounts are strictly evaluated so the footer validation summary automatically clears when all required fields are filled, and does not dismiss prematurely while any required field remains empty.

  5. Regression coverage:

    • Both off-screen and visible missing required fields.
    • Summary clearing immediately after user fills the last missing required field.
    • Multiple missing fields (Amount + Date + Merchant).
    • Split expenses validation flow.
    • Untouched Scans remaining eligible for SmartScan.

What alternative solutions did you explore? (Optional)

  • Auto-scroll only: Does not provide the requested persistent explanation above the button if the user scrolls back down.
  • Show summary for every suppressed error: Incorrectly describes invalid values (e.g. overlength merchant names) as missing fields.
  • Add a separate footer banner component: Unnecessary because ConfirmationFooterContent.tsx already renders the existing FormHelpMessage above the footer button.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 06 '26 18:11 kevinjosh10

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating/editing an expense with a missing required field scrolled off-screen, clicking "Save Expense" appears unresponsive because inline errors are out of view and no message renders above the footer button.

What is the root cause of that problem?

In useFormErrorManagement.ts: isSuppressedInline suppresses common.error.fieldRequired, iou.error.invalidMerchant, and common.error.invalidAmount from computeErrorMessage(). When required field validation fails in useConfirmationValidation, computeErrorMessage() returns undefined, leaving ConfirmationFooterContent.tsx with no error message above the button.

Crucially, competing proposals only handle fieldRequired and miss invalidMerchant when an empty merchant is required under policy rules (useConfirmationValidation.ts line 231), leaving the button unresponsive.

What changes do you think we should make in order to solve the problem?

  1. Localization key: In src/languages/en.ts and src/languages/es.ts, add iou.error.enterRequiredFields ("Please enter the required fields.").

  2. Surface footer summary in useFormErrorManagement.ts: In computeErrorMessage(), return translate('iou.error.enterRequiredFields') when formError === 'common.error.fieldRequired' or formError === 'iou.error.invalidMerchant' && isMerchantRequiredMissing. Preserves inline errors while rendering the general summary above the footer button.

  3. Auto-clearing & Split requests: The existing useEffect in useFormErrorManagement.ts observing missing fields already clears formError once filled. Apply the same check to split bill debounced errors.

Compare branch: https://github.com/Expensify/App/compare/main...camesenin:App:fix-issue-106237?expand=1

What automated tests can you add to prevent this from re-occurring?

In tests/unit/useFormErrorManagementTest.ts:

  • Verify errorMessage returns enterRequiredFields when formError is fieldRequired or missing required merchant.
  • Verify errorMessage clears when all required fields are provided.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83

camesenin avatar Nov 07 '26 00:11 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 07 '26 00:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating or confirming an expense (for example via Spend > Reports > More > Add Expense > Create Expense), if a required field (Amount, Date, or Merchant) is missing and scrolled outside the visible viewport, clicking the footer submit button (Save Expense / Create Expense) appears completely unresponsive because the inline field error is off-screen and the footer summary error is suppressed.

What is the root cause of that problem?

There are two interconnected root causes across src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts and src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts:

  1. useFormErrorManagement.ts unconditionally suppresses common.error.fieldRequired from the footer errorMessage: In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:268-295:

    const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
        error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        if (isSuppressedInline(formError)) {
            return undefined;
        }
        if (isTypeSplit && !shouldShowReadOnlySplits) {
            return debouncedFormError && !isSuppressedInline(debouncedFormError) ? translate(debouncedFormError) : undefined;
        }
    

    When useConfirmationValidation blocks submission with {errorKey: 'common.error.fieldRequired'} (for a missing manual amount, a partially filled manual Scan expense, or a cleared date), isSuppressedInline causes computeErrorMessage() to return undefined. Consequently, ConfirmationFooterContent renders no FormHelpMessage above the footer button.

  2. In manual / workspace flows where Amount and Date are valid but a required Merchant is left blank, useConfirmationValidation returns iou.error.invalidMerchant instead of common.error.fieldRequired: In src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts:183-190:

    if (isMerchantRequired) {
        if (!isEditingSplitBill && !isMerchantFieldValid) {
            return {errorKey: 'iou.error.invalidMerchant'};
        }
        if (isEditingSplitBill && (isMerchantEmpty || (shouldDisplayFieldError && isMerchantMissing(transaction)))) {
            return {errorKey: 'iou.error.invalidMerchant'};
        }
    }
    

    Meanwhile, MerchantField.tsx:87-92 explicitly expects formError === 'common.error.fieldRequired' when isMerchantRequired && !displayMerchantValue:

    if (
        formError === 'common.error.fieldRequired' &&
        (isConfirmationMerchantMissing(merchantState, canEnterScanFieldsManually, isPolicyExpenseChat) || (isMerchantRequired && !displayMerchantValue))
    ) {
        return translate('common.error.fieldRequired');
    }
    

    Because useConfirmationValidation returns 'iou.error.invalidMerchant' even when the merchant field is simply empty/untyped (isMerchantEmpty or isUntypedPlaceholderMerchant(transaction?.isMerchantSet, iouMerchant?.trim() ?? '')), a missing required merchant on a manual workspace expense would NOT trigger common.error.fieldRequired (nor show the footer required-fields summary) unless empty required merchants are distinguished from typed invalid merchants!

What changes do you think we should make in order to solve the problem?

  1. Add the translation key common.error.pleaseEnterRequiredFields in src/languages/en.ts (and corresponding locale files es.ts, fr.ts, de.ts, etc.):

    // src/languages/en.ts under common.error:
    pleaseEnterRequiredFields: 'Please enter the required fields.',
    
  2. Return common.error.fieldRequired when a required merchant is empty/untyped in src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts: When isMerchantRequired is true and the merchant is empty or still holds the untyped default placeholder (isMerchantEmpty || isUntypedPlaceholderMerchant(transaction?.isMerchantSet, merchantValue.trim())), return {errorKey: 'common.error.fieldRequired'} (so both the inline MerchantField required error at lines 88–91 and the footer summary error are triggered consistently), while keeping {errorKey: 'iou.error.invalidMerchant'} for non-empty invalid merchant strings:

    const isMerchantBlank = isMerchantEmpty || isUntypedPlaceholderMerchant(transaction?.isMerchantSet, merchantValue.trim());
    if (isMerchantRequired) {
        if (!isEditingSplitBill && !isMerchantFieldValid) {
            return {errorKey: isMerchantBlank ? 'common.error.fieldRequired' : 'iou.error.invalidMerchant'};
        }
        if (isEditingSplitBill && (isMerchantEmpty || (shouldDisplayFieldError && isMerchantMissing(transaction)))) {
            return {errorKey: 'common.error.fieldRequired'};
        }
    }
    

    And in useFormErrorManagement.ts:228, include (isMerchantRequired && isMerchantBlank) in isMerchantRequiredMissing so the existing auto-clear useEffect at lines 229–236 clears formError as soon as the merchant is entered.

  3. Map common.error.fieldRequired to translate('common.error.pleaseEnterRequiredFields') in src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts: Update isSuppressedInline and computeErrorMessage so that 'common.error.fieldRequired' is no longer suppressed to undefined, and instead renders translate('common.error.pleaseEnterRequiredFields') above the footer button (both in standard confirmation flows and in the editable split branch via debouncedFormError):

    const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
        error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const translateFormError = (error: TranslationPaths): string =>
        error === 'common.error.fieldRequired' ? translate('common.error.pleaseEnterRequiredFields') : translate(error);
    

    And in computeErrorMessage():

    if (isTypeSplit && !shouldShowReadOnlySplits) {
        return debouncedFormError && !isSuppressedInline(debouncedFormError) ? translateFormError(debouncedFormError) : undefined;
    }
    ...
    return formError ? translateFormError(formError) : undefined;
    

    This guarantees:

    • Inline fields (AmountField, DateField, MerchantField) still inspect formError === 'common.error.fieldRequired' and display their per-field inline "This field is required" error.
    • ConfirmationFooterContent receives errorMessage = "Please enter the required fields." and renders it in FormHelpMessage directly above the footer button, even when the invalid field is scrolled out of view.
    • As soon as all required fields (Amount, Date, Merchant) are filled, the existing useEffect in useFormErrorManagement.ts:229-236 sets setFormError('') and clears both the inline errors and the footer summary.
    • We will also update tests/unit/useFormErrorManagementTest.ts and tests/unit/useConfirmationValidationTest.ts to cover the new footer summary message and auto-clearing behavior.

What alternative solutions did you explore? (Optional)

  • Only checking formError === 'common.error.fieldRequired' without updating the blank required merchant branch in useConfirmationValidation.ts: rejected because a manual workspace expense with valid Amount and Date but a blank Merchant returns 'iou.error.invalidMerchant', which would leave the footer blank despite MerchantField.tsx:89 already being wired for formError === 'common.error.fieldRequired'.

zaidrain06 avatar Nov 07 '26 00:11 zaidrain06

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating an expense (e.g. Spend > Reports > More > Create Expense), if a required field such as Amount is missing and scrolled out of view, clicking Save Expense appears to do nothing — the save is correctly blocked, but the inline error is off-screen so the user gets no explanation.

What is the root cause of that problem?

The confirmation step validates required fields on submit and blocks the save, but the only feedback is the field-level inline error. There is no validation summary near the footer button, so when the invalid field is outside the viewport the blocked submit looks like an unresponsive button.

What changes do you think are needed to solve the problem?

In IOURequestStepConfirmation, when submit validation fails, render a visible validation summary immediately above the footer button — "Please enter the required fields." with the standard error indicator — listing that required fields are missing. Keep the existing inline errors on the affected fields, keep invalid submissions blocked (no bypass of validation), and clear the summary as soon as all required-field errors are corrected.

What alternative solutions did you explore?

Auto-scrolling to the first invalid field on failed submit — that helps, but on its own it still leaves the user without an explanation at the point where they clicked; the summary above the button is the requested behaviour and works whether or not scrolling happens. I will implement the summary as specified in the issue's acceptance criteria.

What will you do to verify the fix?

Reproduce the issue flow (amount left empty, scrolled out of view, click Save Expense) and confirm the summary appears above the footer button; confirm the summary also makes sense when the field is visible; correct the field and confirm the summary clears and the expense saves normally; run the existing IOU confirmation tests.

khizzcr7 avatar Nov 07 '26 00:11 khizzcr7

Proposal

Please re-state the problem that we are trying to solve in this issue

When creating/editing an expense (e.g. Spend › Reports › More › Add Expense › Create Expense), if a required field (Amount, Date, or Merchant) is missing and the field is scrolled outside the viewport, clicking Save Expense appears unresponsive. The save is correctly blocked by validation, but computeErrorMessage() in useFormErrorManagement.ts suppresses the common.error.fieldRequired / iou.error.invalidMerchant / common.error.invalidAmount errors from the footer FormHelpMessage, so no validation summary is rendered above the footer button.

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:268-278:

const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
    error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');

const computeErrorMessage = (): string | undefined => {
    if (routeError) {
        return routeError;
    }
    // This runs ahead of the split branch below ...
    if (isSuppressedInline(formError)) {
        return undefined;
    }
    ...

isSuppressedInline returns true for common.error.fieldRequired, meaning computeErrorMessage() returns undefined. ConfirmationFooterContent.tsx receives no errorMessage and renders an empty FormHelpMessage above the footer button. If the invalid field is out of view, the user has zero feedback that anything is wrong.

The existing suppression rationale (documented in lines 263-267) is sound for the normal case — the inline field error already says "This field is required," so showing it again in the footer is redundant. But it breaks down when the field is scrolled off-screen: there is no visible error at all, and the button looks dead.

What changes do you think we should make in order to solve the problem?

1. Add a localization key in src/languages/en.ts (and all locale files: es.ts, fr.ts, de.ts, pt-BR.ts, etc.):

// under common.error:
pleaseEnterRequiredFields: 'Please enter the required fields.',

2. Update computeErrorMessage() in useFormErrorManagement.ts so that the three currently-suppressed "inline" errors (fieldRequired, invalidMerchant, non-distance invalidAmount) are surfaced as the summary message above the footer button instead of being silently dropped:

const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
    error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');

const computeErrorMessage = (): string | undefined => {
    if (routeError) {
        return routeError;
    }
    // These errors are also shown inline on their respective fields, but when the field is
    // scrolled out of view the user gets no feedback at all. Surface a summary message above
    // the footer button so the blocked submit is always explained.
    if (isSuppressedInline(formError)) {
        return translate('common.error.pleaseEnterRequiredFields');
    }
    if (isTypeSplit && !shouldShowReadOnlySplits) {
        if (isSuppressedInline(debouncedFormError)) {
            return translate('common.error.pleaseEnterRequiredFields');
        }
        return debouncedFormError ? translate(debouncedFormError) : undefined;
    }
    if (formError === 'violations.missingAttendees') {
        return undefined;
    }
    if (formError === 'iou.error.invalidTaxAmount') {
        return undefined;
    }
    return formError ? translate(formError) : undefined;
};

Key design points:

  • The distance-amount exception (!isDistanceRequest && error === 'common.error.invalidAmount') is preserved: distance requests still surface invalidAmount via both the inline field and the footer (since the distance-amount field has no inline surface), while non-distance invalidAmount now shows the summary instead of nothing.
  • Inline errors are preserved: the affected field components (AmountField, DateField, MerchantField) independently check formError === 'common.error.fieldRequired' and display their own inline "This field is required" message. The formError state itself is unchanged; only the footer message changes from undefined to the summary.
  • Split flows: the debounced branch is updated symmetrically so split-bill confirmation also shows the summary.

3. Auto-clearing: The existing useEffect at lines 229-236 already clears formError to '' as soon as isAmountRequiredMissing, isDateRequiredMissing, and isMerchantRequiredMissing are all false. Since the footer message is derived from formError via computeErrorMessage(), clearing formError automatically clears the footer summary. No additional clearing logic is needed.

4. Submission blocking preserved: useConfirmationValidation still returns the error key and blocks submission. The fix only changes what is displayed, not what is validated.

What specific scenarios should be covered by automated tests?

  • formError === 'common.error.fieldRequired' → errorMessage returns 'Please enter the required fields.' (standard flow)
  • formError === 'iou.error.invalidMerchant' → errorMessage returns the summary (non-split, merchant required + empty)
  • formError === 'common.error.invalidAmount' (non-distance) → errorMessage returns the summary
  • formError === 'common.error.invalidAmount' (distance request) → errorMessage returns translate('common.error.invalidAmount') (unchanged — distance amount still surfaces in footer)
  • Split flow: debouncedFormError === 'common.error.fieldRequired' → errorMessage returns the summary
  • All required fields filled → formError cleared, errorMessage returns undefined
  • routeError set → errorMessage returns routeError (unchanged priority)

What alternative solutions did you explore?

  • Only show the summary when the field is out of view (detect scroll position): rejected — detecting viewport visibility of a specific field is fragile, platform-dependent, and adds unnecessary complexity. The summary message is useful even when the field is visible (it confirms which action is blocked), matching the acceptance criterion "The error is also understandable when the affected field is visible."
  • Auto-scroll to the first invalid field: considered as a complement, but the issue explicitly asks for a visible validation summary above the footer button. Auto-scroll alone doesn't satisfy the acceptance criteria when multiple fields are missing.

PR

PR will be linked here once assigned.

vanshshah11 avatar Nov 07 '26 00:11 vanshshah11

Proposal

Please re-state the problem that we are trying to solve in this issue.

On the expense confirmation page (Create Expense / Save Expense), when a required field (Amount, Merchant, or Date) is missing and the user scrolls down and taps the footer submit button while that required field is scrolled out of view, no validation error message is displayed above the footer button. As a result, tapping the submit button appears to do nothing when the inline field error is off-screen.

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (lines 27–38), computeErrorMessage() explicitly suppresses field-level required errors from being returned as formError:

  • It defines isSuppressedInline = error === 'common.error.fieldRequired' || (!isDistanceRequest && error === 'common.error.invalidAmount') || error === 'iou.error.invalidMerchant' and returns '' whenever isSuppressedInline is true.

Because computeErrorMessage() returns '' for those errors, formError passed into src/components/MoneyRequestConfirmationList/ConfirmationFooterContent.tsx (lines 90–103) is empty, so ConfirmationFooterContent does not render a FormHelpMessage above the Button in the sticky footer. When the user is on a smaller viewport or has many fields (tags, categories, attendees, tax, etc.) and the invalid Amount, Merchant, or Date row is scrolled out of view, the inline error on the MenuItemWithTopDescription cannot be seen and the footer shows no feedback at all.

What changes do you think we should make in order to solve the problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (and src/components/MoneyRequestConfirmationList/ConfirmationFooterContent.tsx):

  1. Update computeErrorMessage() in useFormErrorManagement.ts so that when Amount, Merchant, or Date validation fails on submit (common.error.fieldRequired, common.error.invalidAmount, or iou.error.invalidMerchant), formError is populated (for example with the corresponding translated error message or 'common.error.fieldRequired' / specific field error message) instead of returning '', so ConfirmationFooterContent.tsx renders the FormHelpMessage directly above the footer confirm button alongside the inline field error.
  2. Ensure clearFormErrors in useFormErrorManagement.ts continues to clear formError as soon as the user edits the missing Amount, Merchant, or Date field.

What alternative solutions did you explore? (Optional)

We also considered auto-scrolling the ScrollView back to the top when a required field error occurs, but the issue specifically requests showing the required-field validation error message above the footer button so users immediately see why submission is blocked at their current scroll position.

jeffrey-graham avatar Nov 07 '26 01:11 jeffrey-graham

📣 @jeffrey-graham! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 01:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On the expense creation confirmation screen, when a user attempts to submit an expense with one or more required fields missing (such as Merchant or Amount), only inline field-level "This field is required" errors appear on the individual list rows. We also need to display a general validation error message ("Please enter the required fields.") in the footer above the primary submit button, and automatically clear it once all required fields are filled.

What is the root cause of that problem?

There are two connected causes in src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts and src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts:

  1. computeErrorMessage() suppresses required-field errors from the footer: In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (lines 268-278):

    const isSuppressedInline = (error: string) =>
        error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        if (!formError || isSuppressedInline(formError)) {
            return undefined;
        }
        return translate(formError);
    };
    

    When required fields are missing on submit, useConfirmationValidation.ts sets formError to either:

    • 'common.error.fieldRequired' (when shouldShowFieldRequiredError is true — e.g. missing category, tag, description, tax, missing scan merchant, or missing manual amount at lines 195-204), or
    • 'iou.error.invalidMerchant' (when a manual expense on a workspace with isMerchantRequired === true has a valid amount and date, so shouldShowFieldRequiredError is false, and execution reaches lines 177-192 of useConfirmationValidation.ts where isMerchantEmpty || isUntypedPlaceholderMerchant(...) sets setFormError('iou.error.invalidMerchant')).

    Because isSuppressedInline returns true for both 'common.error.fieldRequired' and 'iou.error.invalidMerchant', computeErrorMessage() returns undefined, and ConfirmationFooterContent.tsx (lines 194-200) renders no FormHelpMessage above the Button.

  2. Auto-clearing formError in useFormErrorManagement.ts misses manual required merchants (isMerchantRequired): In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (lines 221-236), the effect that clears 'common.error.fieldRequired' when all required fields are filled defines:

    const isMerchantRequiredMissing = isConfirmationMerchantMissing;
    

    where isConfirmationMerchantMissing (lines 147-152) only checks partially entered Scan requests (isScanRequest(transaction)):

    const isConfirmationMerchantMissing = useMemo(() => {
        if (!hasAttemptedConfirm || !isScanRequest(transaction) || isMovingTransactionFromTrackExpense || !hasSmartScanFailedWithMissingFields) {
            return false;
        }
        return !trimmedMerchant || isUntypedPlaceholderMerchant(transaction?.isMerchantSet, trimmedMerchant);
    }, [...]);
    

    For a manual expense on a workspace where isMerchantRequired is true, isConfirmationMerchantMissing is always false! As a result:

    • If both Amount and Merchant are empty on a manual workspace expense, clicking Create sets formError = 'common.error.fieldRequired'. As soon as the user fills in only Amount (while Merchant is still empty), isAmountRequiredMissing becomes false and isMerchantRequiredMissing is already false, so lines 229-235 prematurely clear formError even though the required Merchant is still missing!
    • Conversely, if Amount was already filled and only Merchant was empty, clicking Create sets formError = 'iou.error.invalidMerchant', which is already cleared when Merchant becomes non-empty at lines 204-208.

What changes do you think we should make in order to solve the problem?

  1. Add the translation key common.error.pleaseEnterRequiredFields in src/languages/en.ts (and corresponding locale files):

    pleaseEnterRequiredFields: 'Please enter the required fields.',
    
  2. Include manual required merchant in isMerchantRequiredMissing in src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (lines 204-236): Compute whether a manual required merchant is missing and include it in isMerchantRequiredMissing so 'common.error.fieldRequired' stays active until the required merchant is also filled:

    const isManualMerchantRequiredMissing = Boolean(
        isMerchantRequired && (!trimmedMerchant || isUntypedPlaceholderMerchant(transaction?.isMerchantSet, trimmedMerchant)),
    );
    const isMerchantRequiredMissing = isConfirmationMerchantMissing || isManualMerchantRequiredMissing;
    
  3. Return translate('common.error.pleaseEnterRequiredFields') from computeErrorMessage() in src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts (lines 268-281): When formError represents a required-field validation failure (formError === 'common.error.fieldRequired' or formError === 'iou.error.invalidMerchant' when isMerchantRequiredMissing is true), return translate('common.error.pleaseEnterRequiredFields') so ConfirmationFooterContent displays "Please enter the required fields." above the submit button while keeping inline field-level "This field is required" messages intact:

    const isRequiredFieldFormError =
        formError === 'common.error.fieldRequired' || (formError === 'iou.error.invalidMerchant' && isMerchantRequiredMissing);
    
    const isSuppressedInline = (error: string) =>
        error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        if (isRequiredFieldFormError) {
            return translate('common.error.pleaseEnterRequiredFields');
        }
        if (!formError || isSuppressedInline(formError)) {
            return undefined;
        }
        return translate(formError);
    };
    

What alternative solutions did you explore? (Optional)

  • Changing useConfirmationValidation.ts to set formError = 'common.error.pleaseEnterRequiredFields' directly: useFormErrorManagement.ts checks formError === 'common.error.fieldRequired' and formError === 'iou.error.invalidMerchant' in several effects and inline error computations (getMerchantErrorMessage, showConfirmAmountError, auto-clear effects). Keeping the internal formError state codes unchanged and mapping required-field errors to translate('common.error.pleaseEnterRequiredFields') in computeErrorMessage() avoids breaking any existing inline field validation checks.

e5ash avatar Nov 07 '26 18:11 e5ash

Proposal

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/ConfirmationFooterContent.tsx and ConfirmationListLayout.tsx:

  1. When a required field (such as Amount, Merchant, or Date) is missing or invalid on an expense confirmation screen, validation sets inline errors on the specific field component (in formError / errorFields).
  2. If the user is viewing the bottom of the form or if the fields are scrolled out of the visible viewport, clicking the primary submit button ("Create Expense" / "Save Expense") blocks submission, but provides no visual feedback in the footer area near the button.
  3. The submit button in ConfirmationFooterContent does not pass formError to a footer alert component (such as FormAlertWithSubmitButton or DotIndicatorMessage above the button), causing the tap to appear completely unresponsive to the user.

What changes do you think we should make in order to solve the problem?

  1. In src/components/MoneyRequestConfirmationList/ConfirmationFooterContent.tsx, accept formError / validation error summary and display a DotIndicatorMessage (or render the button via FormAlertWithSubmitButton / FormHelpMessage) directly above the submit button.
  2. When the user taps the submit button and required field validation fails:
    • Display a generic or field-specific validation error message (e.g. common.pleaseFillAllRequiredFields or the first active field error) above the footer button.
    • Automatically scroll the SelectionListWithSections to the first invalid field so the user is immediately brought to the missing field.

What alternative solutions did you explore? (Optional)

Only scrolling to the invalid field without displaying a footer message. However, displaying the validation message directly above the footer button provides immediate feedback right at the point of interaction, matching Expensify's UX guidelines across form submissions.

Contributor Details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0179cdc82689f205c7

TassioSales avatar Nov 08 '26 00:11 TassioSales

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 08 '26 00:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating or confirming an expense (for example via Spend > Reports > More > Add Expense > Create Expense), if a required field such as Amount, Date, or Merchant is missing and scrolled out of the visible viewport, clicking Save Expense / Create Expense appears to do nothing because the inline field error is off-screen and no validation summary message is shown above the footer button.

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:

  1. computeErrorMessage() (lines 268-295) suppresses required-field errors from the footer:

    const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
        error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        // This runs ahead of the split branch below because splits render those same inline fields, so they duplicate the same way.
        if (isSuppressedInline(formError)) {
            return undefined;
        }
    

    When required fields are missing on confirm, useConfirmationValidation.ts sets formError to either 'common.error.fieldRequired' (when Amount, Date, or a partially manually entered Scan Merchant is missing) or 'iou.error.invalidMerchant' (when a manual workspace expense with isMerchantRequired === true has a valid Amount and Date, so shouldShowFieldRequiredError is false, and useConfirmationValidation.ts falls through to the merchant check). Because isSuppressedInline(formError) returns true for both, computeErrorMessage() returns undefined, and ConfirmationFooterContent.tsx renders no FormHelpMessage above the submit button.

  2. Blank required merchants on manual workspace expenses are not tracked by isMerchantRequiredMissing (line 228):

    • At line 228, isMerchantRequiredMissing is computed via isConfirmationMerchantMissing(transaction, canEnterScanFieldsManually, isPolicyExpenseChat).
    • However, in src/libs/MoneyRequestUtils.ts:279, isConfirmationMerchantMissing checks isPartiallyEnteredScanExpense(...), which is only true when isScanRequest(transaction) is true.
    • For a manual workspace expense (isScanRequest === false, isMerchantRequired === true), isConfirmationMerchantMissing is always false. Consequently:
      • If both Amount and Merchant are left blank on a manual workspace expense and the user clicks Create Expense, formError is set to 'common.error.fieldRequired'. As soon as the user fills in Amount (while Merchant is still blank), the auto-clear useEffect at lines 229–236 sees isAmountRequiredMissing === false, isDateRequiredMissing === false, and isMerchantRequiredMissing === false, and prematurely clears formError to '' while the required Merchant is still empty!
      • Conversely, if Merchant has a non-empty invalid value (such as exceeding CONST.MERCHANT_NAME_MAX_BYTES = 255 bytes), formError is 'iou.error.invalidMerchant' with a typed merchant, which should remain suppressed inline rather than displaying "Please enter the required fields.".

What changes do you think we should make in order to solve the problem?

  1. Add the translation key common.error.pleaseEnterRequiredFields ('Please enter the required fields.') in src/languages/en.ts (and the other language files).
  2. In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:
    • Compute isUntypedMerchant (!trimmedMerchant || isUntypedPlaceholderMerchant(transaction?.isMerchantSet, trimmedMerchant)) and include (isMerchantRequired && isUntypedMerchant) in isMerchantRequiredMissing so that common.error.fieldRequired stays active until a required manual merchant is also filled in.
    • Define isRequiredFieldError (error === 'common.error.fieldRequired' || (error === 'iou.error.invalidMerchant' && isMerchantRequiredMissing)) and return translate('common.error.pleaseEnterRequiredFields') in computeErrorMessage() before isSuppressedInline(formError).

What alternative solutions did you explore? (Optional)

  • Returning translate('common.error.pleaseEnterRequiredFields') for all isSuppressedInline errors: Rejected because non-empty invalid field values (e.g. a merchant exceeding 255 bytes or an invalid non-empty amount) are invalid-value errors rather than missing required fields. Checking isRequiredFieldError(formError) ensures "Please enter the required fields." is shown only when required fields are actually missing, and clears immediately once all required fields are entered.

cocvn157 avatar Nov 08 '26 04:11 cocvn157

📣 @cocvn157! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 08 '26 04:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When creating or editing an expense (for example via Spend > Reports > More > Add Expense > Create Expense, or manual/scan confirmation), if a required field (Amount, Date, or Merchant) is missing and scrolled outside the visible viewport, clicking the footer button (Save Expense / Create Expense) appears unresponsive because the inline field error is off-screen and no validation feedback is rendered near the footer button.

What is the root cause of that problem?

In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:

  1. When required fields are missing on confirmation, useConfirmationValidation detects the invalid condition and returns {errorKey: 'common.error.fieldRequired'} (or {errorKey: 'iou.error.invalidMerchant'} when isMerchantRequired && isMerchantEmpty).
  2. However, in useFormErrorManagement.ts:
    const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
        error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    const computeErrorMessage = (): string | undefined => {
        if (routeError) {
            return routeError;
        }
        if (isSuppressedInline(formError)) {
            return undefined;
        }
        ...
    
    isSuppressedInline was originally added to prevent duplicating the field text "This field is required" at the bottom of the form when fields are visible. Because isSuppressedInline(formError) returns true for missing required fields, computeErrorMessage() evaluates to undefined.
  3. Consequently, in src/components/MoneyRequestConfirmationList/ConfirmationFooterContent.tsx:
    {!!errorMessage && (
        <FormHelpMessage
            style={[styles.ph1, styles.mb2]}
            isError
            message={errorMessage}
        />
    )}
    
    no <FormHelpMessage> is displayed above the footer button, leaving the user without any indication of why saving is blocked when the field is outside the viewport.

What changes do you think we should make in order to solve the problem?

  1. Add the translation key common.error.pleaseEnterRequiredFields ('Please enter the required fields.') to src/languages/en.ts and src/languages/es.ts:

    // src/languages/en.ts
    pleaseEnterRequiredFields: 'Please enter the required fields.',
    
    // src/languages/es.ts
    pleaseEnterRequiredFields: 'Por favor, ingrese los campos obligatorios.',
    
  2. In src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts:

    • Identify missing required field errors with a helper:
      const isRequiredFieldMissing = (error: TranslationPaths | ''): boolean =>
          error === 'common.error.fieldRequired' || (error === 'iou.error.invalidMerchant' && isMerchantRequired && isMerchantEmpty);
      
    • In computeErrorMessage():
      • For split requests (isTypeSplit && !shouldShowReadOnlySplits): if isRequiredFieldMissing(debouncedFormError), return translate('common.error.pleaseEnterRequiredFields').
      • For non-split requests: if isRequiredFieldMissing(formError), return translate('common.error.pleaseEnterRequiredFields').
      • Non-empty invalid inputs (e.g. non-distance invalid amounts or a merchant string exceeding CONST.MERCHANT_NAME_MAX_BYTES = 255 bytes) continue through isSuppressedInline(formError) to remain suppressed inline.
    --- a/src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts
    +++ b/src/components/MoneyRequestConfirmationList/hooks/useFormErrorManagement.ts
    @@ -268,11 +268,20 @@ function useFormErrorManagement({
         const isSuppressedInline = (error: TranslationPaths | ''): boolean =>
             error === 'common.error.fieldRequired' || error === 'iou.error.invalidMerchant' || (!isDistanceRequest && error === 'common.error.invalidAmount');
    
    +    const isRequiredFieldMissing = (error: TranslationPaths | ''): boolean =>
    +        error === 'common.error.fieldRequired' || (error === 'iou.error.invalidMerchant' && isMerchantRequired && isMerchantEmpty);
    +
         const computeErrorMessage = (): string | undefined => {
             if (routeError) {
                 return routeError;
             }
    +        if (isTypeSplit && !shouldShowReadOnlySplits) {
    +            if (isRequiredFieldMissing(debouncedFormError)) {
    +                return translate('common.error.pleaseEnterRequiredFields');
    +            }
    +            return debouncedFormError && !isSuppressedInline(debouncedFormError) ? translate(debouncedFormError) : undefined;
    +        }
    +        if (isRequiredFieldMissing(formError)) {
    +            return translate('common.error.pleaseEnterRequiredFields');
    +        }
             // This runs ahead of the split branch below because splits render those same inline fields, so they duplicate the same way.
             if (isSuppressedInline(formError)) {
                 return undefined;
             }
    -        if (isTypeSplit && !shouldShowReadOnlySplits) {
    -            // Splits render the debounced value, so the suppression has to be re-checked against it. `formError` clears
    -            // the instant the user fixes the field while `debouncedFormError` lags by USE_DEBOUNCED_STATE_DELAY, and
    -            // without this the suppressed error would pop into the footer for that window (#96565).
    -            return debouncedFormError && !isSuppressedInline(debouncedFormError) ? translate(debouncedFormError) : undefined;
    -        }
    
  3. Behavior and Auto-clearing:

    • The specific inline errors on the individual field components (AmountField, DateField, MerchantField) remain untouched and continue displaying their specific messages.
    • When the user fills in the missing required field(s), the existing auto-clear useEffect hooks in useFormErrorManagement.ts (lines 217–222 for merchant, and lines 229–236 for amount/date) automatically reset formError to ''. This sets errorMessage back to undefined, immediately clearing <FormHelpMessage> above the footer button and unblocking confirmation.

What alternative solutions did you explore? (Optional)

  • Returning translate('common.error.pleaseEnterRequiredFields') for all isSuppressedInline errors: Rejected because non-empty invalid values (such as an invalid non-empty amount or a merchant string exceeding 255 bytes) are invalid-format errors rather than missing required fields; they already render specific inline feedback. Checking isRequiredFieldMissing ensures the summary message specifically explains missing required fields as requested in the issue discussion.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

ayolyn avatar Nov 08 '26 19:11 ayolyn

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 08 '26 19:11 melvin-bot[bot]

@TaduJR please move forward with Melvin for this, or add Help wanted and evaluate proposal from the community. Thanks.

trjExpensify avatar Nov 09 '26 17:11 trjExpensify

@trjExpensify

Was already working this. Will finish reviewing after some hours.

Thanks!

TaduJR avatar Nov 09 '26 17:11 TaduJR

@MelvinBot

Please post a proposal

TaduJR avatar Nov 09 '26 18:11 TaduJR