Skip to content

Build your personal knowledge base with Trilium Notes

attribute dialog doesn't allow to (attempt to) save relation without target note

azivner5bf5d1cac42f
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js
index 4ec89f8611..599d3a9388 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 964b3aa937..2b525eff3a 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 4040a189a0..8d91ea044a 100644
--- a/src/views/dialogs/attributes.ejs
+++ b/src/views/dialogs/attributes.ejs
@@ -48,6 +48,10 @@
<input class="form-control relation-target-note-id"
placeholder="search for note by its name"
data-bind="noteAutocomplete, value: relationValue, valueUpdate: 'blur', event: { blur: $parent.attributeChanged }">
+
+ <div style="color: red" data-bind="if: $parent.isEmptyRelationTarget($index())">Relation target note
+ can't be empty.
+ </div>
</div>
<div data-bind="visible: type == 'label-definition'">