Skip to content

Commit a735cbf

Browse files
smayo-gplsstephanieleary
authored andcommitted
lp2097555 OPAC_Expert_Search_Rows_Delete
Fixes to simple.js so that expert search can add and delete rows again. Plugs the Aria announcement status from Advanced Search into Expert Search, since that has to exist to use the same functions for adding and deleting rows. Fixes bug where new Expert Search rows are created already filled with the same values as the first row. Signed-off-by: Steven Mayo <[email protected]> Signed-off-by: Garry Collum <[email protected]> Signed-off-by: Stephanie Leary <[email protected]>
1 parent 425d5b1 commit a735cbf

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

Open-ILS/src/templates-bootstrap/opac/parts/advanced/expert.tt2

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="row my-2">
1010
<div class="col-md-6">
1111
<div id="adv_expert_rows_here">
12-
<fieldset class="row row-cols-auto align-items-end" id="adv_expert_row">
12+
<fieldset class="row row-cols-auto align-items-end adv_expert_row" id="adv_expert_row">
1313
<legend class="visually-hidden">[% l('Expert search term group 1') %]</legend>
1414

1515
<div class="col-auto col-marc-tag d-inline-block">
@@ -25,19 +25,29 @@
2525
<input class="form-control" id="expert_term" type="search" name="term" />
2626
</div>
2727
<div class="col-auto col-row-remove">
28-
<button type="button" class="btn btn-remove btn-sm row-remover my-1" onclick="removeSearchRows($event)">
28+
<button type="button" class="btn btn-remove btn-sm row-remover my-1" onclick="killRowIfAtLeast(1, event)">
2929
<i class="fas fa-times" aria-hidden="true" title="[% l('Remove search term group 1') %]"></i>
3030
<span class="visually-hidden">[% l('Remove search term group 1') %]</span>
3131
</button>
3232
</div>
3333
</fieldset>
3434
</div>
3535
<div class="row mt-2">
36-
<div class="col-md-12">
36+
<div class="col-md-10 d-flex align-items-start justify-content-between">
3737
<button type="button" class="btn btn-opac btn-sm my-1" onclick="addExpertRow()">
3838
<i class="fas fa-plus-circle" aria-hidden="true"></i>
3939
[% l("Add Search Terms") %]
4040
</button>
41+
42+
<div id="expert_search_status" role="status">
43+
[% # ARIA live announcements toggled by ariaStatus() in simple.js %]
44+
<div class="m-0 alert alert-warning d-none" id="aria-search-row-removed">
45+
[% l('Search term logic group removed.'); %]
46+
</div>
47+
<div class="m-0 alert alert-success d-none" id="aria-search-row-added">
48+
[% l('Search term logic group added.'); %]
49+
</div>
50+
</div>
4151
</div>
4252
</div>
4353
</div>

Open-ILS/web/js/ui/default/opac/simple.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,30 @@ function addSearchRow() {
4141
}
4242

4343
function addExpertRow() {
44-
const clone = document.getElementById('adv_expert_row').cloneNode(true);
44+
// Needs to use class instead of id so you can delete the first row
45+
const clone = document.getElementsByClassName('adv_expert_row')[0].cloneNode(true);
4546
clone.id = '';
47+
// Clear input values in the new row
48+
clone.getElementsByTagName("input").forEach(input => {
49+
input.value = '';
50+
});
4651
const parent = document.getElementById("adv_expert_rows_here");
4752
parent.appendChild(clone);
53+
displayAlert('aria-search-row-added');
4854
reindexLegends(parent);
4955
}
5056

51-
function killRowIfAtLeast(min) {
57+
function killRowIfAtLeast(min, $event) {
5258
const link = $event.target;
53-
//console.debug("Target: ", link);
54-
var row = link.parentNode.parentNode;
55-
//console.debug("Row: ", row);
56-
if (row.parentNode.getElementsByTagName("fieldset").length > min) {
57-
row.parentNode.removeChild(row);
59+
let row = link.closest("fieldset");
60+
let parent = row.parentNode;
61+
if (parent.getElementsByTagName("fieldset").length > min) {
62+
parent.removeChild(row);
5863
displayAlert('aria-search-row-removed');
5964
// re-number the legends
60-
reindexLegends(tBody);
65+
reindexLegends(parent);
6166
// focus on first input in last row
62-
row.parentNode.querySelector('input').focus();
67+
parent.querySelector('input').focus();
6368
}
6469
}
6570

0 commit comments

Comments
 (0)