Skip to content

Commit

Permalink
fix: broker agency search functionality broken (#4886)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbodine1 committed Jan 5, 2025
1 parent 3ee3927 commit 865d69b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
45 changes: 43 additions & 2 deletions app/assets/javascripts/inline_replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $(document).on('click', '#priorSepModal .btn-confirmation', function() {
return false;
});

$(document).on('click', '.broker-staff-registration-container button.search', function() {
$(document).on('click', '.broker-staff-registration-container span.search', function() {
// components/benefit_sponsors/app/views/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/_new_staff_applicant.html.erb
brokerSearch();
return false
Expand Down Expand Up @@ -311,4 +311,45 @@ $(document).on('click', '#confirm_member', function (e) {
if ($(this).closest('form')[0].checkValidity()) {
$(this).removeClass('disabled').attr('tabindex', 0);
}
});
});

/// components/benefit_sponsors/app/views/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/_new_staff_applicant.html.erb
$(document).on('turbolinks:load ajax:success', function () {
console.log('turbolinks:load ajax:success');
validateAjaxForm();
});

function brokerSearch() {
console.log('brokerSearch');
var broker_agency_search = document.getElementById(
'staff_agency_search'
).value;
var broker_registration_page = document.getElementById(
'staff_is_broker_registration_page'
).value;
document.getElementById('broker-staff-btn').disabled = true;
if (broker_agency_search != undefined) {
$.ajax({
url: '/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/search_broker_agency.js',
type: 'GET',
data: {
q: broker_agency_search,
broker_registration_page: broker_registration_page,
},
});
}
}

function selectBrokereAgency(element) {
var result = document.querySelectorAll('.result');
result.forEach(function (result) {
var elements = result.querySelectorAll('.staff-select-broker');
elements.forEach(function (ele) {
ele.classList.remove('agency-selected');
});
});
document.getElementById('staff_profile_id').value =
element.dataset.broker_agency_profile_id;
element.closest('.staff-select-broker').classList.add('agency-selected');
document.getElementById('broker-staff-btn').disabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
<div class="row search-dropdown-wrapper">
<div class="col-md-12 col-sm-12 col-xs-12 px-0">

<%= f.label :agency_search, l10n("broker_agencies.broker_roles.search_broker_agencies"), class: 'pl-3' %>
<%= f.label :agency_search, l10n("broker_agencies.broker_roles.search_broker_agencies"), class: 'pl-3' %>
<div class="col-md-12 col-sm-10 col-xs-12 input-group d-flex align-items-center justify-content-start">
<%= f.hidden_field :profile_id %>
<%= f.hidden_field :profile_type, value: "broker_agency_staff" %>
<%= f.hidden_field :is_broker_registration_page, value: true %>
<%= f.text_field :agency_search, placeholder: "#{l10n('broker_agencies.broker_roles.agency_name_placeholder')}", class: 'form-control w-50 rounded' %>
<div class="input-group-btn ml-2">
<button class="btn btn-select search short" href="#" data-loading-text="Loading...">
<span tabindex="0" class="btn btn-select search short" href="#" id="search" data-keydown-id="search" data-loading-text="Loading...">
<i class="fa fa-search"></i>
<%= l10n("search").to_s %>
</button>
</span>
</div>
</div>
</div>
Expand All @@ -52,32 +52,4 @@
<% end %>
</div>

<script>
validateAjaxForm();

function brokerSearch() {
var broker_agency_search = document.getElementById('staff_agency_search').value;
var broker_registration_page = document.getElementById('staff_is_broker_registration_page').value;
document.getElementById('broker-staff-btn').disabled = true;
if (broker_agency_search != undefined) {
$.ajax({
url: '/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/search_broker_agency.js',
type: "GET",
data: {'q': broker_agency_search, "broker_registration_page": broker_registration_page}
});
}
}

function selectBrokereAgency(element) {
var result = document.querySelectorAll('.result');
result.forEach(function (result) {
var elements = result.querySelectorAll('.staff-select-broker');
elements.forEach(function (ele) {
ele.classList.remove("agency-selected");
});
});
document.getElementById('staff_profile_id').value = element.dataset.broker_agency_profile_id;
element.closest(".staff-select-broker").classList.add('agency-selected');
document.getElementById('broker-staff-btn').disabled = false;
}
</script>

0 comments on commit 865d69b

Please sign in to comment.