diff --git a/ui/components/controls/Link.vue b/ui/components/controls/Link.vue index fa74c868..ea8d6f6c 100644 --- a/ui/components/controls/Link.vue +++ b/ui/components/controls/Link.vue @@ -78,9 +78,19 @@ export default { }); newDoc.on('afterInsert', (data) => { + // if new doc was created + // then set the name of the doc in input this.handleChange(newDoc.name); this.$modal.hide(); }); + + this.$modal.observable().on('modal.hide', () => { + // if new doc was not created + // then reset the input value + if (this.value === '__newItem') { + this.handleChange(''); + } + }) } }) } diff --git a/ui/plugins/modal.js b/ui/plugins/modal.js index c06300f4..25088690 100644 --- a/ui/plugins/modal.js +++ b/ui/plugins/modal.js @@ -14,6 +14,10 @@ export default { hide() { Bus.trigger('hideModal'); + }, + + observable() { + return Bus; } } @@ -22,9 +26,21 @@ export default { return { registered: false, modalVisible: false, - modalOptions: {} + modalOptions: {}, + modalListeners: {} } }, + + watch: { + modalVisible(value) { + if (value === true) { + Bus.trigger('modal.show'); + } else { + Bus.trigger('modal.hide'); + } + } + }, + created: function () { if (this.registered) return; @@ -35,6 +51,7 @@ export default { Bus.on('hideModal', () => { this.modalVisible = false; + this.modalOptions = {}; }); this.registered = true;