From 23a2b58b24c04db83e82439f5d76e4c3cbf3cc83 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 5 Feb 2018 21:07:18 -0500 Subject: [PATCH] fix #32, could not open attribute dialog if it didn't have any attributes yet --- src/public/javascripts/dialogs/attributes.js | 9 ++++----- src/views/index.ejs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index 91ca2c849..8b6318c10 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -22,7 +22,8 @@ const attributesDialog = (function() { attributeNames = await server.get('attributes/names'); - $(".attribute-name:last").focus(); + // attribute might not be rendered immediatelly so could not focus + setTimeout(() => $(".attribute-name:last").focus(), 100); }; function isValid() { @@ -65,9 +66,9 @@ const attributesDialog = (function() { function addLastEmptyRow() { const attrs = self.attributes(); - const last = attrs[attrs.length - 1](); + const last = attrs.length === 0 ? null : attrs[attrs.length - 1](); - if (last.name.trim() !== "" || last.value !== "") { + if (!last || last.name.trim() !== "" || last.value !== "") { self.attributes.push(ko.observable({ attributeId: '', name: '', @@ -149,8 +150,6 @@ const attributesDialog = (function() { $(this).autocomplete("search", $(this).val()); }); - $(document).on('blur', '.attribute-name', function (e) { console.log("blur!"); }); - $(document).on('focus', '.attribute-value', async function (e) { if (!$(this).hasClass("ui-autocomplete-input")) { const attributeName = $(this).parent().parent().find('.attribute-name').val(); diff --git a/src/views/index.ejs b/src/views/index.ejs index fc04c89c7..12a1ada99 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -389,7 +389,7 @@