Skip to content
Snippets Groups Projects
Commit 902ae9c0 authored by Pierre-Jean CHANCELLIER's avatar Pierre-Jean CHANCELLIER
Browse files

add search input for lexicon

parent 31e64d74
No related branches found
No related tags found
No related merge requests found
<template> <template>
<main class="container"> <main class="container">
<h2 class="text-center mb-5 font-weight-light">{{ $t("lexique") }}</h2> <h2 class="text-center mb-5 font-weight-light">{{ $t("lexique") }}</h2>
<div class="row">
<div class="col-md-6 mx-auto">
<div class="form-group">
<input
v-model="search"
type="text"
class="form-control"
id="exampleFormControlInput1"
placeholder="Votre recherche" />
</div>
</div>
</div>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
...@@ -9,8 +21,8 @@ ...@@ -9,8 +21,8 @@
</thead> </thead>
<tbody> <tbody>
<tr v-for="mot in listeMotsTrad" :key="mot.title"> <tr v-for="mot in listeMotsTrad" :key="mot.title">
<th scope="row">{{ mot.title }}</th> <th scope="row" v-html="mot.title"></th>
<td>{{ mot.desc }}</td> <td v-html="mot.desc"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -32,6 +44,7 @@ export default { ...@@ -32,6 +44,7 @@ export default {
active: true active: true
} }
], ],
search: "",
listeMots: [ listeMots: [
"dossier", "dossier",
"adhesion", "adhesion",
...@@ -68,14 +81,39 @@ export default { ...@@ -68,14 +81,39 @@ export default {
es: "/lexico" es: "/lexico"
} }
}, },
methods: {
wrapSearch(str, txt) {
if (str == "") {
return txt
}
return txt.replace(new RegExp(str, "gi"), "<mark>$&</mark>")
}
},
computed: { computed: {
listeMotsTrad() { listeMotsTrad() {
let retour = [] let retour = []
this.listeMots.forEach((el) => { this.listeMots.forEach((el) => {
retour.push({ let isFound = false
desc: this.$t(el + ".desc"), let desc = this.$t(el + ".desc")
title: this.$t(el + ".title") let title = this.$t(el + ".title")
})
if (desc.toLowerCase().includes(this.search.toLowerCase())) {
desc = this.wrapSearch(this.search, desc)
isFound = true
}
if (title.toLowerCase().includes(this.search.toLowerCase())) {
title = this.wrapSearch(this.search, title)
isFound = true
}
if (isFound) {
retour.push({
desc: desc,
title: title
})
}
}) })
retour.sort((a, b) => { retour.sort((a, b) => {
if (a.title < b.title) { if (a.title < b.title) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment