Skip to content

Commit

Permalink
Highlight search term in variant select
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed May 28, 2024
1 parent 0e4d6de commit ca4d033
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/assets/javascripts/alchemy/solidus/admin/variant_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ $.fn.alchemyVariantSelect = function (options) {
: variant.name
}

function formatResult(variant) {
function formatResult(variant, _el, query) {
const matchTerm = new RegExp(query.term, "gi")
const formatMatch = (match) => `<em>${match}</em>`
const name = variant.name.replace(matchTerm, formatMatch)
const sku = variant.sku.replace(matchTerm, formatMatch)
return `
<div class="variant-select-result">
<div>
<span>${variant.name}</span>
<span>${name}</span>
</div>
<div>
<span>${variant.options_text}</span>
<span>${variant.sku}</span>
<span>${sku}</span>
</div>
</div>
`
Expand Down

0 comments on commit ca4d033

Please sign in to comment.