fix filtering of names

This commit is contained in:
Julie Lenaerts 2022-01-19 15:13:22 +01:00
parent 21d5f974eb
commit 2811e61439

View File

@ -126,16 +126,29 @@
return string.charAt(0).toUpperCase() + string.slice(1);
}
let searchFragments = location.hash.substring(1).split('%20')
searchFragments = searchFragments.filter((el) => el.startsWith("firstname") || el.startsWith("lastname"))
const uri = decodeURI(location.hash.substring(1))
console.log(uri)
let searchFragments = uri.split(' ')
console.log(searchFragments)
searchFragments = searchFragments.filter((el) => {
if ( ( el.startsWith("firstname") || el.startsWith("lastname") ) || (el !== '' && !el.startsWith('birthdate') && !el.startsWith('gender') && !el.startsWith('city') && !el.startsWith('phonenumber') && !el.startsWith('@'))) {
return el
}
})
console.log('after filter', searchFragments)
searchFragments = searchFragments.map((el) => {
if (el.startsWith("firstname")) {
return el.slice(10)
} else {
return el.slice(9)
} else if (el.startsWith("lastname")) {
return el.slice(10)
}
return el.replace('\"', '')
})
console.log(searchFragments)
if (searchFragments) {
const suggestions = searchFragments.map((el) => `<p class="name badge bg-person" style="cursor: pointer; margin-right: 5px;">${capitalizeFirstLetter(el)}</p>`)
const suggestFirstName = document.getElementById("suggest-firstname")
@ -145,12 +158,11 @@
suggestLastname.innerHTML = suggestions.join(' ');
}
const tags = document.getElementsByClassName('name')
const tags = document.querySelectorAll('.name')
for (let i=0; i < tags.length; i++) {
const tag = tags[i]
tag.onclick = function(e) {
const field = e.target.parentElement.id === 'suggest-lastname' ? document.getElementById('lastname-field') : document.getElementById('firstname-field')
tags.forEach((tag) => {
tag.addEventListener('click', function(e) {
const field = e.target.parentElement.id === 'suggest-lastname' ? document.getElementById('lastname-field') : document.getElementById('firstname-field')
const suggestion = e.target.parentElement.id === 'suggest-lastname' ? e.target.textContent.toUpperCase() : e.target.textContent
if (field.value === '') {
@ -163,8 +175,9 @@
[...document.querySelectorAll("p")]
.filter(p => p.textContent.includes(e.target.textContent))
.forEach(p => p.style.display = "none")
}
}
})
})
</script>
{% endblock js %}