diff --git a/app/javascript/controllers/savings_goal_stepper_controller.js b/app/javascript/controllers/savings_goal_stepper_controller.js index 796ee058f..b4faa2990 100644 --- a/app/javascript/controllers/savings_goal_stepper_controller.js +++ b/app/javascript/controllers/savings_goal_stepper_controller.js @@ -15,6 +15,9 @@ export default class extends Controller { "step2Circle", "stepperLine", "modalSubtitle", + "nameInput", + "amountInput", + "avatarPreview", "linkedAccountCheckbox", "initialContributionAmount", "initialContributionAccountSelect", @@ -23,7 +26,6 @@ export default class extends Controller { "reviewAccounts", "reviewSuggested", "footerLeftButton", - "footerLeftLabel", "footerRightButton", "submitButton", ]; @@ -91,6 +93,14 @@ export default class extends Controller { this.updateReview(); } + nameChanged() { + if (!this.hasAvatarPreviewTarget || !this.hasNameInputTarget) return; + const name = this.nameInputTarget.value.trim(); + const initial = name ? name.charAt(0).toUpperCase() : "?"; + const inner = this.avatarPreviewTarget.querySelector('[data-testid="savings-goal-avatar"]'); + if (inner) inner.textContent = initial; + } + validateStep1() { const requiredInputs = this.step1PanelTarget.querySelectorAll( 'input[name="savings_goal[name]"], input[name="savings_goal[target_amount]"]' @@ -163,9 +173,12 @@ export default class extends Controller { } updateFooter() { - if (this.hasFooterLeftLabelTarget) { - this.footerLeftLabelTarget.textContent = - this.currentStep === 1 ? this.cancelLabelValue : this.backLabelValue; + if (this.hasFooterLeftButtonTarget) { + const labelSpan = this.footerLeftButtonTarget.querySelector("span"); + if (labelSpan) { + labelSpan.textContent = + this.currentStep === 1 ? this.cancelLabelValue : this.backLabelValue; + } } if (this.hasFooterRightButtonTarget) { const labelSpan = this.footerRightButtonTarget.querySelector("span"); diff --git a/app/views/savings_goals/_form_stepper.html.erb b/app/views/savings_goals/_form_stepper.html.erb index 1f29bfae6..064ef1446 100644 --- a/app/views/savings_goals/_form_stepper.html.erb +++ b/app/views/savings_goals/_form_stepper.html.erb @@ -27,9 +27,9 @@