Commit a0d1a575 authored by Marc Egger's avatar Marc Egger

Revert "refs #10117" This makes me sad

This reverts commit 4e0a1025
parent 4e0a1025
Pipeline #3281 passed with stages
in 3 minutes and 29 seconds
......@@ -79,7 +79,6 @@ var QfqNS = QfqNS || {};
$element.attr(attributeName, attributeValue);
if (attributeName.toLowerCase() === "value") {
$element.val(attributeValue);
$element.trigger('qfqChange');
}
};
......
......@@ -62,16 +62,9 @@ var QfqNS = QfqNS || {};
var suggestions = new Bloodhound(bloodhoundConfiguration);
suggestions.initialize();
// create actual input field
var $inputField = $('<input/>', {
type: 'text',
class: $element.attr('class')
});
$element.after($inputField);
// prevent form submit when enter key is pressed
$inputField.off('keyup');
$inputField.on('keypress keyup', function (e) {
$element.off('keyup');
$element.on('keypress keyup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
e.preventDefault();
......@@ -98,9 +91,9 @@ var QfqNS = QfqNS || {};
};
// initialize tagsManager
var tagApi = $inputField.tagsManager({
var tagApi = $element.tagsManager({
deleteTagsOnBackspace: false,
hiddenTagListName: '',
hiddenTagListName: $element.attr('name'),
tagClass: 'qfq-typeahead-tag',
delimiters: delimiters,
validator: !!$element.data('typeahead-pedantic') ? pedanticValidator : null,
......@@ -117,21 +110,13 @@ var QfqNS = QfqNS || {};
});
// when the hidden input field changes, overwrite value with tag object list
tagApi.bind('tm:hiddenUpdate', function (e, tags) {
tagApi.bind('tm:hiddenUpdate', function (e, tags, hiddenInput) {
var tagObjects = $.map(tags, function (t) {
return existingTags.filter(function (tt) {return tt.value === t;})[0];
});
$element.val(JSON.stringify(tagObjects));
});
// if value of hidden field is changed externally, update tagManager
$element.on('qfqChange', function () {
existingTags = $element.val() !== '' ? JSON.parse($element.val()) : [];
tagApi.tagsManager('empty');
$.each(existingTags, function (i, tag) {
tagApi.tagsManager('pushTag', tag.value);
});
hiddenInput.val(JSON.stringify(tagObjects));
});
$element.removeAttr('name');
// add existing tags
$.each(existingTags, function (i, tag) {
......@@ -139,7 +124,7 @@ var QfqNS = QfqNS || {};
});
// add typahead
$inputField.typeahead({
$element.typeahead({
// options
hint: n.TypeAhead.getHint($element),
highlight: n.TypeAhead.getHighlight($element),
......@@ -155,20 +140,20 @@ var QfqNS = QfqNS || {};
// No message if field is not set to pedantic.
notFound: (function ($_) {
return function (obj) {
if (!!$element.data('typeahead-pedantic'))
if (!!$_.data('typeahead-pedantic'))
return "<div>'" + n.TypeAhead.htmlEncode(obj.query) + "' not found";
};
})($inputField)
})($element)
}
});
// directly add tag when clicked on in typahead menu
$inputField.bind('typeahead:selected', function (event, sugg) {
$element.bind('typeahead:selected', function (event, sugg) {
tagApi.tagsManager("pushTag", sugg.value);
});
// update typahead list when typahead changes
$inputField.bind('typeahead:render', function (event, sugg) {
$element.bind('typeahead:render', function (event, sugg) {
typeaheadList.length = 0;
typeaheadList.push.apply(typeaheadList, sugg);
});
......
......@@ -141,7 +141,7 @@
</div>
<div class="col-md-6">
<input id="tags1" type="hidden" class="form-control qfq-typeahead" name="tags1"
<input id="tags1" type="text" class="form-control qfq-typeahead" name="tags1"
data-typeahead-sip="abcdef"
data-typeahead-limit="10"
data-typeahead-minlength="1"
......@@ -160,7 +160,7 @@
</div>
<div class="col-md-6">
<input id="tags2" type="hidden" class="form-control qfq-typeahead" name="tags2"
<input id="tags2" type="text" class="form-control qfq-typeahead" name="tags2"
data-typeahead-sip="abcdef"
data-typeahead-limit="10"
data-typeahead-minlength="1"
......
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