Commit e55abf05 authored by Marc Egger's avatar Marc Egger

now works with tags as well. add initial suggestions to static list

parent 43e68c47
Pipeline #3338 passed with stages
in 3 minutes and 58 seconds
......@@ -97,6 +97,15 @@ var QfqNS = QfqNS || {};
var staticList = $element.data('typeahead-tag-static-list');
staticList = staticList !== undefined && staticList !== '' ? staticList : [];
// get initial suggestions
var initialSuggestions = $element.data('typeahead-initial-suggestion');
initialSuggestions = initialSuggestions !== undefined && initialSuggestions !== '' ? initialSuggestions : [];
$.each(initialSuggestions, function(i, tag) {
if (!staticList.filter(function(t) {return t.key === tag.key;})) {
staticList.push(tag);
}
});
// list of current typeahead suggestions
var typeaheadList = existingTags.slice();
var typeaheadListApi = [];
......@@ -175,7 +184,7 @@ var QfqNS = QfqNS || {};
{
name: 'staticList',
display: 'value',
source: n.TypeAhead.substringMatcher(staticList),
source: n.TypeAhead.substringMatcher(staticList, initialSuggestions),
limit: n.TypeAhead.getLimit($element),
templates: {
// header: '<h3 class="league-name">List</h3>',
......@@ -258,6 +267,11 @@ var QfqNS = QfqNS || {};
// get initial suggestions
var initialSuggestions = $element.data('typeahead-initial-suggestion');
initialSuggestions = initialSuggestions !== undefined && initialSuggestions !== '' ? initialSuggestions : [];
$.each(initialSuggestions, function(i, tag) {
if (!staticList.filter(function(t) {return t.key === tag.key;})) {
staticList.push(tag);
}
});
// get key from field value and fetch value from staticList (and later from API if SIP given)
var filledFromStaticList = n.TypeAhead.fillTypeAheadFromShadowElementStaticList($element, staticList);
......
......@@ -82,6 +82,7 @@
<?php
$staticList = [
['value' => "duplicate", 'key' => "duplicate"],
['value' => "one", 'key' => "1"],
['value' => "two", 'key' => "2"],
['value' => "three", 'key' => "3"],
......@@ -94,6 +95,7 @@
$staticListSafeJson = htmlentities(json_encode($staticList), ENT_QUOTES, 'UTF-8');
$initialSuggestions = [
['value' => "duplicate", 'key' => "duplicate"],
['value' => "one2", 'key' => "1x"],
['value' => "two2", 'key' => "2x"],
['value' => "three2", 'key' => "3x"],
......@@ -116,7 +118,9 @@
<div class="col-md-6">
<input id="dropdown1" type="text" class="form-control qfq-typeahead" name="dropdown1"
data-typeahead-sip="abcde" data-typeahead-minlength="1" data-typeahead-limit="3"
data-typeahead-sip="abcde"
data-typeahead-minlength="1"
data-typeahead-limit="3"
data-typeahead-tag-static-list="<?php echo $staticListSafeJson; ?>"
data-typeahead-initial-suggestion="<?php echo $initialSuggestionsSafeJson; ?>"
>
......@@ -164,18 +168,6 @@
$tagsSafeJson = htmlentities(json_encode($tags), ENT_QUOTES, 'UTF-8');
$staticTags = [
['value' => "one", 'key' => "1"],
['value' => "two", 'key' => "2"],
['value' => "three", 'key' => "3"],
['value' => "four", 'key' => "4"],
['value' => "five", 'key' => "5"],
['value' => "six", 'key' => "6"],
['value' => "seven", 'key' => "7"],
];
$staticTagsSafeJson = htmlentities(json_encode($staticTags), ENT_QUOTES, 'UTF-8');
?>
<div id="formgroup4" class="form-group">
......@@ -191,7 +183,8 @@
data-typeahead-tags="true"
data-typeahead-tag-delimiters="[9, 13]"
data-typeahead-tag-static-list="<?php echo $staticTagsSafeJson; ?>"
data-typeahead-tag-static-list="<?php echo $staticListSafeJson; ?>"
data-typeahead-initial-suggestion="<?php echo $initialSuggestionsSafeJson; ?>"
value="<?php echo $tagsSafeJson; ?>"
>
</div>
......@@ -212,7 +205,8 @@
data-typeahead-tags="true"
data-typeahead-pedantic="true"
data-typeahead-tag-delimiters="[9, 44]"
data-typeahead-tag-static-list="<?php echo $staticTagsSafeJson; ?>"
data-typeahead-tag-static-list="<?php echo $staticListSafeJson; ?>"
data-typeahead-initial-suggestion="<?php echo $initialSuggestionsSafeJson; ?>"
value="<?php echo $tagsSafeJson; ?>"
>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment