forked from dict/alar.ink
Fix autocomp behaviour to ignore non-Kannada inputs and always select the first suggestion.
This commit is contained in:
@@ -58,7 +58,7 @@
|
||||
</select>
|
||||
<div class="input-group">
|
||||
<input autofocus autocomplete="off" required placeholder="" aria-label="Search word"
|
||||
type="text" id="q" name="q" value="{{ if .Data.Query }}{{ .Data.Query.Query }}{{ end }}" data-autocomp-autoselect="true" />
|
||||
type="text" id="q" name="q" value="{{ if .Data.Query }}{{ .Data.Query.Query }}{{ end }}" data-autocomp-autoselect="false" />
|
||||
<button type="submit" aria-label="Search"><img src="/static/search.svg?v={{ .AssetVer }}" alt="{{- .L.T "global.btnSearch" -}}" /></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -122,7 +122,7 @@ function autocomp(el, options = {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
val = opt.onSelect(items[idx]);
|
||||
val = opt.onSelect(items[idx], items);
|
||||
el.value = val || items[idx];
|
||||
}
|
||||
|
||||
|
||||
@@ -298,8 +298,12 @@ async function screenshotElement(element) {
|
||||
});
|
||||
},
|
||||
|
||||
onSelect: (val) => {
|
||||
// autocomp search isn't complete. Use the user's input instead of autocomp selection.
|
||||
onSelect: (val, items) => {
|
||||
// If the val is English, then pick the first item from items and use that.
|
||||
if (/^[A-Za-z0-9\-,'" ]+$/.test(val) && items.length > 0) {
|
||||
val = items[0];
|
||||
}
|
||||
|
||||
if (val) {
|
||||
elQ.value = val;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user