Browse Source

Make partial slightly more generic

pull/72/head
baarkerlounger 4 years ago
parent
commit
3aee0b976d
  1. 4
      app/validations/soft_validations.rb
  2. 6
      app/views/form/_validation_override_question.html.erb

4
app/validations/soft_validations.rb

@ -9,12 +9,12 @@ private
net_income_errors = {} net_income_errors = {}
if weekly_net_income && person_1_economic_status && override_net_income_validation.blank? if weekly_net_income && person_1_economic_status && override_net_income_validation.blank?
if weekly_net_income < applicable_income_range.soft_min && weekly_net_income > applicable_income_range.hard_min if weekly_net_income < applicable_income_range.soft_min && weekly_net_income > applicable_income_range.hard_min
net_income_errors["weekly_net_income"] = OpenStruct.new( net_income_errors["override_net_income_validation"] = OpenStruct.new(
message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?", message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}", hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
) )
elsif weekly_net_income > applicable_income_range.soft_max && weekly_net_income < applicable_income_range.hard_max elsif weekly_net_income > applicable_income_range.soft_max && weekly_net_income < applicable_income_range.hard_max
net_income_errors["weekly_net_income"] = OpenStruct.new( net_income_errors["override_net_income_validation"] = OpenStruct.new(
message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?", message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}", hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
) )

6
app/views/form/_validation_override_question.html.erb

@ -1,11 +1,11 @@
<div class="govuk-form-group govuk-form-group--error"> <div class="govuk-form-group govuk-form-group--error">
<%= f.govuk_check_boxes_fieldset :override_net_income_validation, <%= f.govuk_check_boxes_fieldset @case_log.soft_errors.keys.first,
legend: { text: @case_log.soft_errors.values.first.message, size: "l" }, legend: { text: @case_log.soft_errors.values.first.message, size: "l" },
hint: { text: @case_log.soft_errors.values.first.hint_text } do %> hint: { text: @case_log.soft_errors.values.first.hint_text } do %>
<%= f.govuk_check_box :override_net_income_validation, "override_net_income_validation", <%= f.govuk_check_box @case_log.soft_errors.keys.first, @case_log.soft_errors.keys.first,
label: { text: "Yes" }, label: { text: "Yes" },
checked: f.object.send("override_net_income_validation") checked: f.object.send(@case_log.soft_errors.keys.first)
%> %>
<% end %> <% end %>
</div> </div>

Loading…
Cancel
Save