From d3e44b37e992da04ac2feef7a3ec16e2b4382f20 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 6 Aug 2018 22:52:49 +0200 Subject: [PATCH] autocomplete for promoted text labels --- .../javascripts/services/note_detail.js | 20 +++++++++++++++++++ src/routes/api/attributes.js | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index a95d9731e..fddbfba9d 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -265,6 +265,26 @@ async function loadAttributes() { if (valueAttr.type === 'label') { if (definition.labelType === 'text') { $input.prop("type", "text"); + + const attributeValues = await server.get('attributes/values/' + encodeURIComponent(valueAttr.name)); + + if (attributeValues.length === 0) { + return; + } + + $input.autocomplete({ + // shouldn't be required and autocomplete should just accept array of strings, but that fails + // because we have overriden filter() function in autocomplete.js + source: attributeValues.map(attribute => { + return { + attribute: attribute, + value: attribute + } + }), + minLength: 0 + }); + + $input.focus(() => $input.autocomplete("search", "")); } else if (definition.labelType === 'number') { $input.prop("type", "number"); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index f0deb03ac..50cd05801 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -138,7 +138,7 @@ async function getAttributeNames(req) { async function getValuesForAttribute(req) { const attributeName = req.params.attributeName; - return await sql.getColumn("SELECT DISTINCT value FROM attributes WHERE isDeleted = 0 AND name = ? AND value != '' ORDER BY value", [attributeName]); + return await sql.getColumn("SELECT DISTINCT value FROM attributes WHERE isDeleted = 0 AND name = ? AND type = 'label' AND value != '' ORDER BY value", [attributeName]); } module.exports = {