Commit 5d315ac0 authored by Marc Egger's avatar Marc Egger
Browse files

Merge branch '10115TypeAheadStaticList' into '10115ThypeAheadStaticList2'

merge changes into fixes

See merge request !254
parents b2b18e21 cb20b815
Pipeline #3294 passed with stages
in 3 minutes and 28 seconds
...@@ -158,23 +158,43 @@ var QfqNS = QfqNS || {}; ...@@ -158,23 +158,43 @@ var QfqNS = QfqNS || {};
hint: n.TypeAhead.getHint($element), hint: n.TypeAhead.getHint($element),
highlight: n.TypeAhead.getHighlight($element), highlight: n.TypeAhead.getHighlight($element),
minLength: n.TypeAhead.getMinLength($element) minLength: n.TypeAhead.getMinLength($element)
}, { },
{
display: 'value', display: 'value',
source: suggestions, source: suggestions,
limit: n.TypeAhead.getLimit($element), limit: n.TypeAhead.getLimit($element),
templates: { templates: {
header: '<h3 class="league-name">API</h3>',
suggestion: function (obj) { suggestion: function (obj) {
return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>"; return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>";
}, },
// No message if field is not set to pedantic. // No message if field is not set to pedantic.
notFound: (function ($_) { notFound: (function ($_) {
return function (obj) { return function (obj) {
if (!!$element.data('typeahead-pedantic')) if (!!$element.data('typeahead-pedantic') && typeaheadList.length === 0)
return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found"; return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found" + JSON.stringify(typeaheadList);
}; };
})($inputField) })($inputField)
} }
}); },
{
display: 'value',
source: n.TypeAhead.substringMatcher(['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']), // suggestions,
limit: n.TypeAhead.getLimit($element),
templates: {
header: '<h3 class="league-name">List</h3>',
suggestion: function (obj) {
return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>";
}// ,
// // No message if field is not set to pedantic.
// notFound: (function ($_) {
// return function (obj) {
// if (!!$element.data('typeahead-pedantic'))
// return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found";
// };
// })($inputField)
}
});
// directly add tag when clicked on in typahead menu // directly add tag when clicked on in typahead menu
$inputField.bind('typeahead:selected', function (event, sugg) { $inputField.bind('typeahead:selected', function (event, sugg) {
...@@ -286,6 +306,27 @@ var QfqNS = QfqNS || {}; ...@@ -286,6 +306,27 @@ var QfqNS = QfqNS || {};
} }
}; };
n.TypeAhead.substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
var substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push({key: str, value: str});
}
});
cb(matches);
};
};
n.TypeAhead.makePedanticHandler = function (bloodhound) { n.TypeAhead.makePedanticHandler = function (bloodhound) {
return function (event) { return function (event) {
......
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<input id="tags1" type="hidden" class="form-control qfq-typeahead" name="tags1" <input id="tags1" type="hidden" class="form-control qfq-typeahead" name="tags1"
data-typeahead-sip="abcdef" data-typeahead-sip="abcdef"
data-typeahead-limit="10" data-typeahead-limit="10"
data-typeahead-minlength="1" data-typeahead-minlength="1"
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<input id="tags2" type="hidden" class="form-control qfq-typeahead" name="tags2" <input id="tags2" type="hidden" class="form-control qfq-typeahead" name="tags2"
data-typeahead-sip="abcdef" data-typeahead-sip="abcdef"
data-typeahead-limit="10" data-typeahead-limit="10"
data-typeahead-minlength="1" data-typeahead-minlength="1"
......
Supports Markdown
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