mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Append the facet value to the facet query on click
This commit is contained in:
parent
d25a859985
commit
510df4729c
@ -34,6 +34,8 @@ $('#query, #facet').on('input', function () {
|
|||||||
for (value of data.facets[facet_name]) {
|
for (value of data.facets[facet_name]) {
|
||||||
const elem = document.createElement('span');
|
const elem = document.createElement('span');
|
||||||
elem.classList.add("tag");
|
elem.classList.add("tag");
|
||||||
|
elem.setAttribute('data-name', facet_name);
|
||||||
|
elem.setAttribute('data-value', value);
|
||||||
elem.innerHTML = `${facet_name}:${value}`;
|
elem.innerHTML = `${facet_name}:${value}`;
|
||||||
facets.appendChild(elem);
|
facets.appendChild(elem);
|
||||||
}
|
}
|
||||||
@ -67,6 +69,19 @@ $('#query, #facet').on('input', function () {
|
|||||||
results.appendChild(elem);
|
results.appendChild(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When we click on a tag we append the facet value
|
||||||
|
// at the end of the facet query.
|
||||||
|
$('#facets .tag').on('click', function () {
|
||||||
|
let name = $(this).attr("data-name");
|
||||||
|
let value = $(this).attr("data-value");
|
||||||
|
|
||||||
|
let facet_query = $('#facet').val().trim();
|
||||||
|
if (facet_query === "") {
|
||||||
|
$('#facet').val(`${name} = "${value}"`).trigger('input');
|
||||||
|
} else {
|
||||||
|
$('#facet').val(`${facet_query} AND ${name} = "${value}"`).trigger('input');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
beforeSend: function () {
|
beforeSend: function () {
|
||||||
if (request !== null) {
|
if (request !== null) {
|
||||||
@ -88,8 +103,8 @@ $('#db-size').text(function(index, text) {
|
|||||||
return filesize(parseInt(text))
|
return filesize(parseInt(text))
|
||||||
});
|
});
|
||||||
|
|
||||||
// We trigger the input when we load the script, this way
|
// We trigger the input when we load the script.
|
||||||
// we execute a placeholder search when the input is empty.
|
|
||||||
$(window).on('load', function () {
|
$(window).on('load', function () {
|
||||||
|
// We execute a placeholder search when the input is empty.
|
||||||
$('#query').trigger('input');
|
$('#query').trigger('input');
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#facets {
|
#facets {
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
margin: 20px auto 0 auto;
|
margin: 20px auto 0 auto;
|
||||||
@ -16,6 +17,10 @@
|
|||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#facets .tag:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#logo-white {
|
#logo-white {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user