Skip to content

Commit

Permalink
[rubyforgood#5777] Solve bug around validation when navigating backwards
Browse files Browse the repository at this point in the history
  • Loading branch information
priyapower committed Jul 17, 2024
1 parent 07a5b1b commit f627948
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
28 changes: 16 additions & 12 deletions app/components/form/step_navigation_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<div>
<%# Back navigation %>
<%= button_tag type: @submit_back ? "submit" : "button", class: "btn btn-link", title: "Back step", aria: { label: "Back step" } do %>
<% if @submit_back %>
<%= button_tag type: @submit_back ? :submit : :button,
name: :nav_step,
value: @nav_back,
class: "btn btn-link",
title: "Back step",
aria: { label: "Back step" },
disabled: !@nav_back do %>
<%= link_to @nav_back, title: "Back step", aria: { label: "Back step" } do %>
<i class="lni lni-chevron-left", alt: "Chevron icon left"></i>
<% else %>
<%= link_to @nav_back, title: "Back step", aria: { label: "Back step" } do %>
<i class="lni lni-chevron-left", alt: "Chevron icon left"></i>
<% end %>
<% end %>
<% end %>
<%# Next navigation %>
<%= button_tag type: @submit_next ? "submit" : "button", class: "btn btn-link", title: "Next step", aria: { label: "Next step" } do %>
<% if @submit_next %>
<%= button_tag type: @submit_next ? :submit : :button,
name: :nav_step,
value: @nav_forward,
class: "btn btn-link",
title: "Next step",
aria: { label: "Next step" },
disabled: !@nav_next do %>
<%= link_to @nav_next, title: "Next step", aria: { label: "Next step" } do %>
<i class="lni lni-chevron-right", alt: "Chevron icon right"></i>
<% else %>
<%= link_to @nav_next, title: "Next step", aria: { label: "Next step" } do %>
<i class="lni lni-chevron-right", alt: "Chevron icon right"></i>
<% end %>
<% end %>
<% end %>
</div>
2 changes: 0 additions & 2 deletions app/components/form/step_navigation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ def initialize(nav_back: nil, nav_next: nil, submit_back: false, submit_next: fa
@nav_next = nav_next
@submit_back = submit_back
@submit_next = submit_next
@back_disabled = !@nav_back
@next_disabled = !@nav_next
end
end
3 changes: 3 additions & 0 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ def update
authorize @case_contact
@page = wizard_steps.index(step) + 1
@total_pages = steps.count
@nav_step = params[:nav_step]
params[:case_contact][:status] = step.to_s if !@case_contact.active?
remove_unwanted_contact_types
remove_nil_draft_ids
if @case_contact.update(case_contact_params)
respond_to do |format|
format.html {
render @nav_step.split('/').last.to_sym if @nav_step.present?
if step == steps.last
finish_editing
else
Expand Down Expand Up @@ -154,3 +156,4 @@ def set_steps
self.steps = CaseContact.find(params[:case_contact_id]).form_steps
end
end

3 changes: 2 additions & 1 deletion app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def form_steps
end

def casa_org_any_expenses_enabled?
creator.casa_org.additional_expenses_enabled || creator.casa_org.show_driving_reimbursement
# creator.casa_org.additional_expenses_enabled || creator.casa_org.show_driving_reimbursement
return true
end

private_class_method def self.sorted_by_params
Expand Down
1 change: 0 additions & 1 deletion app/views/case_contacts/form/details.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div>
<%= form_with(model: @case_contact, url: wizard_path(nil, case_contact_id: @case_contact.id), local: true, id: "casa-contact-form", class: "component-validated-form") do |form| %>
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact details", step: @page, total_steps: @total_pages, navigable: Form::StepNavigationComponent.new(nav_back: leave_case_contacts_form_path, nav_next: next_wizard_path, submit_back: false, submit_next: true))) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/case_contacts/form/expenses.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact expenses", step: @page, total_steps: @total_pages)) %>
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact expenses", step: @page, total_steps: @total_pages, navigable: Form::StepNavigationComponent.new(nav_back: previous_wizard_path, nav_next: next_wizard_path, submit_back: true, submit_next: true))) %>

<div>
<%= form_with(model: @case_contact, url: wizard_path(nil, case_contact_id: @case_contact.id), local: true, id: "casa-contact-form", class: "component-validated-form") do |form| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/case_contacts/form/notes.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div data-controller="autosave" data-autosave-good-alert-class="text-muted" data-autosave-bad-alert-class="text-danger">
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact notes", step: @page, total_steps: @total_pages, notes: @case_contact.decorate.form_page_notes[:notes], autosave: true)) %>

<div>
<%= form_with(model: @case_contact, url: wizard_path(nil, case_contact_id: @case_contact.id), id: "casa-contact-form", class: "component-validated-form", data: { "turbo-action": "advance", "autosave-target": "form" }) do |form| %>
<%= render(Form::TitleComponent.new(title: @case_contact.decorate.form_title, subtitle: "Contact notes", step: @page, total_steps: @total_pages, notes: @case_contact.decorate.form_page_notes[:notes], autosave: true, navigable: Form::StepNavigationComponent.new(nav_back: previous_wizard_path, nav_next: @case_contact.casa_org_any_expenses_enabled? ? next_wizard_path : nil, submit_back: true, submit_next: true))) %>
<%= render "contact_topic_notes", form: %>
<div class="card-style-1 pl-25 pr-25 mb-10">
<div class="d-flex justify-content-between mb-3"
Expand Down

0 comments on commit f627948

Please sign in to comment.