Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beta.ordbok.uib.no
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Språksamlingane
beta.ordbok.uib.no
Commits
68cbe4e5
Commit
68cbe4e5
authored
3 years ago
by
Henrik Askjer
Browse files
Options
Downloads
Patches
Plain Diff
Keep auto-select-first
parent
a2eacf9e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/Autocomplete.vue
+22
-11
22 additions, 11 deletions
src/components/Autocomplete.vue
with
22 additions
and
11 deletions
src/components/Autocomplete.vue
+
22
−
11
View file @
68cbe4e5
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
return-object
return-object
rounded
rounded
hide-no-data
hide-no-data
auto-select-first
no-filter
no-filter
hide-details
hide-details
label="Søk..."
label="Søk..."
...
@@ -37,7 +38,7 @@
...
@@ -37,7 +38,7 @@
export
default
{
export
default
{
props
:
{
props
:
{
endpoint
:
String
endpoint
:
String
,
},
},
data
:
function
()
{
data
:
function
()
{
return
{
return
{
...
@@ -45,14 +46,15 @@
...
@@ -45,14 +46,15 @@
items
:
[],
items
:
[],
search
:
null
,
search
:
null
,
select
:
null
,
select
:
null
,
suggesting
:
null
,
debounced
:
debounce
(
function
(
q
,
self
)
{
debounced
:
debounce
(
function
(
q
,
self
)
{
self
.
loading
=
true
self
.
loading
=
true
return
axios
.
get
(
self
.
endpoint
+
'
suggest?q=
'
+
encodeURIComponent
(
q
))
return
axios
.
get
(
self
.
endpoint
+
'
suggest?q=
'
+
encodeURIComponent
(
q
))
.
then
(
.
then
(
function
(
response
)
{
function
(
response
)
{
if
(
self
.
load
ing
)
{
if
(
self
.
suggest
ing
)
{
let
hits
=
[]
let
hits
=
[]
if
(
q
==
self
.
search
)
{
if
(
q
==
self
.
$refs
.
autocomplete
.
search
Input
)
{
response
.
data
.
forEach
((
item
,
i
)
=>
{
response
.
data
.
forEach
((
item
,
i
)
=>
{
let
match
=
encodeURIComponent
(
item
.
match
)
let
match
=
encodeURIComponent
(
item
.
match
)
...
@@ -69,16 +71,22 @@
...
@@ -69,16 +71,22 @@
});
});
hits
.
reverse
()
hits
.
reverse
()
hits
=
hits
.
slice
(
0
,
9
)
hits
=
hits
.
slice
(
0
,
9
)
}
hits
.
sort
(
(
h1
,
h2
)
=>
{
hits
.
sort
(
(
h1
,
h2
)
=>
{
let
val1
=
h1
.
label
.
length
*
10
+
(
h1
.
label
[
0
].
toLowerCase
()
===
h1
.
label
[
0
]
?
0
:
1
)
let
val1
=
h1
.
label
.
length
*
10
+
(
h1
.
label
[
0
].
toLowerCase
()
===
h1
.
label
[
0
]
?
0
:
1
)
let
val2
=
h2
.
label
.
length
*
10
+
(
h2
.
label
[
0
].
toLowerCase
()
===
h2
.
label
[
0
]
?
0
:
1
)
let
val2
=
h2
.
label
.
length
*
10
+
(
h2
.
label
[
0
].
toLowerCase
()
===
h2
.
label
[
0
]
?
0
:
1
)
return
val1
-
val2
return
val1
-
val2
})
})
let
currentSearch
=
self
.
$refs
.
autocomplete
.
searchInput
self
.
items
=
hits
if
(
q
==
currentSearch
)
{
self
.
loading
=
false
self
.
items
=
hits
}
self
.
items
.
push
({
currentSearch
:
encodeURIComponent
(
currentSearch
),
label
:
currentSearch
+
'
'
})
}
}
}
self
.
loading
=
false
})
})
},
100
)
},
100
)
}
}
...
@@ -96,15 +104,18 @@
...
@@ -96,15 +104,18 @@
if
(
typeof
item
===
'
string
'
)
{
if
(
typeof
item
===
'
string
'
)
{
item
=
{
"
q
"
:
encodeURIComponent
(
item
)}
item
=
{
"
q
"
:
encodeURIComponent
(
item
)}
}
}
this
.
loading
=
false
this
.
items
=
[]
this
.
suggesting
=
false
this
.
$emit
(
'
submit
'
,
item
)
this
.
$emit
(
'
submit
'
,
item
)
let
self
=
this
setTimeout
(()
=>
this
.
$refs
.
autocomplete
.
blur
(),
1
)
setTimeout
(()
=>
self
.
$refs
.
autocomplete
.
$refs
.
input
.
select
(),
1
)
}
}
}
}
},
},
methods
:
{
methods
:
{
run_query
(
q
)
{
run_query
(
q
)
{
this
.
items
=
[]
this
.
suggesting
=
true
this
.
debounced
(
q
,
this
)
this
.
debounced
(
q
,
this
)
}
}
},
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment