diff --git a/components/financial_assistance/app/assets/javascripts/financial_assistance/income.js b/components/financial_assistance/app/assets/javascripts/financial_assistance/income.js index 33f51646366..086c8c02c3f 100644 --- a/components/financial_assistance/app/assets/javascripts/financial_assistance/income.js +++ b/components/financial_assistance/app/assets/javascripts/financial_assistance/income.js @@ -59,16 +59,27 @@ function startEditingIncome(income_kind) { } function checkDate(income_id) { - var startDate = $('#start_on_' + income_id).datepicker('getDate'); - var endDate = $('#end_on_' + income_id).datepicker('getDate'); + var startDate = $('#start_on_' + income_id) + var endDate = $('#end_on_' + income_id) - if (endDate != '' && endDate != null && endDate < startDate) { + if (endDate && new Date(endDate.val()) <= new Date(startDate.val())) { alert('The end date must be after the start date.'); - $('#end_on_' + income_id)[0].value = ''; + endDate.val(''); window.event.preventDefault(); } } +$(document).on('submit', 'form[data-income-id]', function() { + checkDate($(this).data('income-id')); +}); + +$(document).on('change', 'form[data-income-id] input[type="date"]', function () { + var form = $(this).parents('form'); + if (form.data('income-and-deduction-date-warning-flag')) { + validateDateWarnings(form.data('income-id')) + } +}); + function currentlyEditing() { return ( $('.interaction-click-control-continue').hasClass('disabled') || diff --git a/components/financial_assistance/app/assets/javascripts/financial_assistance/shared.js b/components/financial_assistance/app/assets/javascripts/financial_assistance/shared.js index b202a704c29..0f15ee282a4 100644 --- a/components/financial_assistance/app/assets/javascripts/financial_assistance/shared.js +++ b/components/financial_assistance/app/assets/javascripts/financial_assistance/shared.js @@ -3,11 +3,12 @@ function getDateFieldDate(id) { return dateValue ? new Date(dateValue) : null; }; -function validateDateWarnings(id, use_bs4 = false) { +function validateDateWarnings(id) { + var useBs4 = document.documentElement.dataset.bs4 const startDateId = "#start_on_" + id; const endDateId = ("#end_on_" + id); - var startDate = use_bs4 ? getDateFieldDate(startDateId) : $(startDateId).datepicker('getDate'); - var endDate = use_bs4 ? getDateFieldDate(endDateId) : $(endDateId).datepicker('getDate'); + var startDate = useBs4 ? getDateFieldDate(startDateId) : $(startDateId).datepicker('getDate'); + var endDate = useBs4 ? getDateFieldDate(endDateId) : $(endDateId).datepicker('getDate'); var today = new Date(); var requiresStartDateWarning = startDate > today var requiresEndDateWarning = endDate diff --git a/components/financial_assistance/app/helpers/financial_assistance/application_helper.rb b/components/financial_assistance/app/helpers/financial_assistance/application_helper.rb index bba825a6d96..118efc80caa 100644 --- a/components/financial_assistance/app/helpers/financial_assistance/application_helper.rb +++ b/components/financial_assistance/app/helpers/financial_assistance/application_helper.rb @@ -115,16 +115,14 @@ def state_options %w[AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA PR RI SC SD TN TX UT VA VI VT WA WV WI WY] end - def income_form_for(application, applicant, income) + def income_form_for(application, applicant, income, &block) url = if income.new_record? application_applicant_incomes_path(application, applicant) else application_applicant_income_path(@application, @applicant, income) end - form_for income, url: url, remote: true do |f| - yield f - end + form_for income, url: url, remote: true, data: {income_id: income.id.to_s, income_and_deduction_date_warning_flag: FinancialAssistanceRegistry[:income_and_deduction_date_warning].enabled?}, &block end def benefit_form_for(application, applicant, benefit) diff --git a/components/financial_assistance/app/views/financial_assistance/incomes/_job_income.html.erb b/components/financial_assistance/app/views/financial_assistance/incomes/_job_income.html.erb index c6f7756db94..08293cb5e9d 100644 --- a/components/financial_assistance/app/views/financial_assistance/incomes/_job_income.html.erb +++ b/components/financial_assistance/app/views/financial_assistance/incomes/_job_income.html.erb @@ -50,8 +50,8 @@
- <%= l10n("faa.other_incomes.remove") %> - <%=l10n("edit")%> + <%= l10n("faa.other_incomes.remove") %> + <%=l10n("edit")%>
<%= f.label :start_on, l10n("faa.other_incomes.start_date"), class: "required", for: "start_on_#{dummy_income_id}" %> - <%= f.date_field :start_on, min: 110.years.ago, max:"9999-12-31", required: true, id: "start_on_#{dummy_income_id}", onchange: onchange_date, class: "w-100" %> + <%= f.date_field :start_on, min: 110.years.ago, max:"9999-12-31", required: true, id: "start_on_#{dummy_income_id}", class: "w-100" %>
<%= f.label :end_on, l10n("faa.other_incomes.end_date"), for: "end_on_#{dummy_income_id}" %> - <%= f.date_field :end_on, min: 110.years.ago, max:"9999-12-31", id: "end_on_#{dummy_income_id}", onchange: onchange_date, class: "w-100 end-on-field" %> + <%= f.date_field :end_on, min: 110.years.ago, max:"9999-12-31", id: "end_on_#{dummy_income_id}", class: "w-100 end-on-field" %>
- Cancel - <%= f.submit l10n("faa.other_incomes.save"), class: 'button btn-save ml-1', :data => { :cuke => "job-income-save-button" }, onclick: "checkDate('#{income_id}')" %> + Cancel + <%= f.submit l10n("faa.other_incomes.save"), class: 'button btn-save ml-1', :data => { :cuke => "job-income-save-button" } %>
diff --git a/components/financial_assistance/app/views/financial_assistance/incomes/_self_employed_income_form.erb b/components/financial_assistance/app/views/financial_assistance/incomes/_self_employed_income_form.erb index 6a8459f64a4..e9a6ee8c9d1 100644 --- a/components/financial_assistance/app/views/financial_assistance/incomes/_self_employed_income_form.erb +++ b/components/financial_assistance/app/views/financial_assistance/incomes/_self_employed_income_form.erb @@ -32,7 +32,7 @@
<%= l10n("cancel") %> - <%= f.submit l10n("faa.other_incomes.save"), class: "button btn-save ml-1", :data => { :cuke => "self-employed-income-save-button" }, onclick: "checkDate('#{income_id}')" %> + <%= f.submit l10n("faa.other_incomes.save"), class: "button btn-save ml-1", :data => { :cuke => "self-employed-income-save-button" } %>
diff --git a/components/financial_assistance/app/views/financial_assistance/incomes/index.html.erb b/components/financial_assistance/app/views/financial_assistance/incomes/index.html.erb index f6316fc6373..ae24605691f 100755 --- a/components/financial_assistance/app/views/financial_assistance/incomes/index.html.erb +++ b/components/financial_assistance/app/views/financial_assistance/incomes/index.html.erb @@ -19,7 +19,7 @@ <%= radio_button_tag("has_job_income", true, @applicant.has_job_income, class: "radio", required: true) %> <%= l10n("yes") %> -