From 5bf5d1cac42fb8826b9d9fe6c7ed959b00008d3c Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 19 Nov 2018 21:58:52 +0100 Subject: [PATCH] attribute dialog doesn't allow to (attempt to) save relation without target note --- src/public/javascripts/dialogs/attributes.js | 8 +++++++- src/public/javascripts/services/note_autocomplete.js | 2 +- src/views/dialogs/attributes.ejs | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index 4ec89f861..599d3a938 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -114,7 +114,7 @@ function AttributesModel() { function isValid() { for (let attributes = self.ownedAttributes(), i = 0; i < attributes.length; i++) { - if (self.isEmptyName(i)) { + if (self.isEmptyName(i) || self.isEmptyRelationTarget(i)) { return false; } } @@ -212,6 +212,12 @@ function AttributesModel() { return cur.name.trim() === "" && !cur.isDeleted && (cur.attributeId !== "" || cur.labelValue !== "" || cur.relationValue); }; + this.isEmptyRelationTarget = function(index) { + const cur = self.ownedAttributes()[index](); + + return cur.type === "relation" && !cur.isDeleted && cur.name && !cur.relationValue; + }; + this.getTargetAttribute = function(target) { const context = ko.contextFor(target); const index = context.$index(); diff --git a/src/public/javascripts/services/note_autocomplete.js b/src/public/javascripts/services/note_autocomplete.js index 964b3aa93..2b525eff3 100644 --- a/src/public/javascripts/services/note_autocomplete.js +++ b/src/public/javascripts/services/note_autocomplete.js @@ -92,7 +92,7 @@ function initNoteAutocomplete($el, options) { $el.on('autocomplete:selected', (event, suggestion) => $el.setSelectedPath(suggestion.path)); $el.on('autocomplete:closed', () => { if (!$el.val().trim()) { - $el.setSelectedPath(""); + clearText($el); } }); } diff --git a/src/views/dialogs/attributes.ejs b/src/views/dialogs/attributes.ejs index 4040a189a..8d91ea044 100644 --- a/src/views/dialogs/attributes.ejs +++ b/src/views/dialogs/attributes.ejs @@ -48,6 +48,10 @@ + +
Relation target note + can't be empty. +