mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
fix filtering of names
This commit is contained in:
parent
21d5f974eb
commit
2811e61439
@ -126,16 +126,29 @@
|
|||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let searchFragments = location.hash.substring(1).split('%20')
|
const uri = decodeURI(location.hash.substring(1))
|
||||||
searchFragments = searchFragments.filter((el) => el.startsWith("firstname") || el.startsWith("lastname"))
|
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) => {
|
searchFragments = searchFragments.map((el) => {
|
||||||
if (el.startsWith("firstname")) {
|
if (el.startsWith("firstname")) {
|
||||||
return el.slice(10)
|
return el.slice(10)
|
||||||
} else {
|
} else if (el.startsWith("lastname")) {
|
||||||
return el.slice(9)
|
return el.slice(10)
|
||||||
}
|
}
|
||||||
|
return el.replace('\"', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(searchFragments)
|
||||||
|
|
||||||
if (searchFragments) {
|
if (searchFragments) {
|
||||||
const suggestions = searchFragments.map((el) => `<p class="name badge bg-person" style="cursor: pointer; margin-right: 5px;">${capitalizeFirstLetter(el)}</p>`)
|
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")
|
const suggestFirstName = document.getElementById("suggest-firstname")
|
||||||
@ -145,12 +158,11 @@
|
|||||||
suggestLastname.innerHTML = suggestions.join(' ');
|
suggestLastname.innerHTML = suggestions.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags = document.getElementsByClassName('name')
|
const tags = document.querySelectorAll('.name')
|
||||||
|
|
||||||
for (let i=0; i < tags.length; i++) {
|
tags.forEach((tag) => {
|
||||||
const tag = tags[i]
|
tag.addEventListener('click', function(e) {
|
||||||
tag.onclick = function(e) {
|
const field = e.target.parentElement.id === 'suggest-lastname' ? document.getElementById('lastname-field') : document.getElementById('firstname-field')
|
||||||
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
|
const suggestion = e.target.parentElement.id === 'suggest-lastname' ? e.target.textContent.toUpperCase() : e.target.textContent
|
||||||
|
|
||||||
if (field.value === '') {
|
if (field.value === '') {
|
||||||
@ -163,8 +175,9 @@
|
|||||||
[...document.querySelectorAll("p")]
|
[...document.querySelectorAll("p")]
|
||||||
.filter(p => p.textContent.includes(e.target.textContent))
|
.filter(p => p.textContent.includes(e.target.textContent))
|
||||||
.forEach(p => p.style.display = "none")
|
.forEach(p => p.style.display = "none")
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock js %}
|
{% endblock js %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user