diff --git a/app/assets/javascripts/financial_assistance.js b/app/assets/javascripts/financial_assistance.js new file mode 100644 index 00000000000..5adfd5a37e8 --- /dev/null +++ b/app/assets/javascripts/financial_assistance.js @@ -0,0 +1,67 @@ +// Initialize the dependent person form +$(document).on('ajax:success', '#edit-dependent-person', function (event) { + $.inputMasks(); + + $('#applicant_same_with_primary').on('click', function () { + if ($(this).is(':checked')) { + $('#applicant-home-address-area').addClass('hidden'); + } else { + $('#applicant-home-address-area').removeClass('hidden'); + } + }); + + $(document).on('click', 'button#delete_applicant_button', function (e) { + e.preventDefault(); + $('#destroyApplicant').modal(); + + $('#destroyApplicant .modal-cancel-button').on('click', function (e) { + console.log('cancel'); + $('#destroyApplicant').modal('hidden'); + }); + $('.btn-confirmation').removeAttr('disabled'); + }); + + $(document).on('click', '#destroyApplicant #destroy-confirm', function (e) { + confirmDestoyApplicant(e, $(this).data('url')); + }); + + function confirmDestoyApplicant(event, url) { + $('.btn-confirmation').prop('disabled', true); + event.preventDefault(); + event.stopImmediatePropagation(); + // + $('.modal-backdrop').removeClass('modal-backdrop'); + $('.modal-open').removeClass('modal-open'); + + $.ajax({ + url: url, + type: 'DELETE', + dataType: 'script', + contentType: false, + processData: false, + }); + } + + $(document).off('click', '#confirm_member'); + $(document).on('click', '#confirm_member', function (e) { + if ($('input#applicant_same_with_primary').length) { + if ($('input#applicant_same_with_primary').is(':checked')) { + $( + '#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required' + ).removeAttr('required'); + } else { + $( + '#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required' + ).attr('required', true); + } + + $('.btn-confirmation').removeAttr('disabled'); + } + $(this).addClass('disabled').attr('tabindex', -1).blur(); + PersonValidations.manageRequiredValidations($('#confirm_member')); + + if ($(this).closest('form')[0].checkValidity()) { + $(this).removeClass('disabled').attr('tabindex', 0); + } + }); +}); diff --git a/components/financial_assistance/app/views/financial_assistance/applicants/_edit.html.erb b/components/financial_assistance/app/views/financial_assistance/applicants/_edit.html.erb index ba5993cd33d..406138168a5 100644 --- a/components/financial_assistance/app/views/financial_assistance/applicants/_edit.html.erb +++ b/components/financial_assistance/app/views/financial_assistance/applicants/_edit.html.erb @@ -139,7 +139,7 @@ <%= f.button(id: 'confirm-member', class: "btn btn-primary hidden") do %> <%= l10n("confirm_member") %> <% end %> - + <%= l10n("confirm_member") %> @@ -156,71 +156,13 @@ - <% else %> <%= form_for @applicant, url: application_applicant_path(@application, @applicant), method: :patch do |f|%>