From de970a4abaa54da1c46e2b0b133709532a41f650 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 25 Aug 2015 23:52:45 +0100 Subject: [PATCH] Fix new tags disappearing in PSM when saving post closes #5708 - when adding a tag give it a throwaway UUID so that every selected/available tag object has a unique identifier for use with selectize --- ghost/admin/app/controllers/post-settings-menu.js | 4 ++++ ghost/admin/app/models/post.js | 1 + ghost/admin/app/templates/post-settings-menu.hbs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ghost/admin/app/controllers/post-settings-menu.js b/ghost/admin/app/controllers/post-settings-menu.js index 50d3193fa8..9e589dbed2 100644 --- a/ghost/admin/app/controllers/post-settings-menu.js +++ b/ghost/admin/app/controllers/post-settings-menu.js @@ -493,6 +493,10 @@ export default Ember.Controller.extend(SettingsMenuMixin, { tagToAdd = self.get('store').createRecord('tag', { name: tagName }); + + // we need to set a UUID so that selectize has a unique value + // it will be ignored when sent to the server + tagToAdd.set('uuid', Ember.guidFor(tagToAdd)); } // push tag onto post relationship diff --git a/ghost/admin/app/models/post.js b/ghost/admin/app/models/post.js index 99c0f18fe7..d81c8ea076 100644 --- a/ghost/admin/app/models/post.js +++ b/ghost/admin/app/models/post.js @@ -59,6 +59,7 @@ export default DS.Model.extend(ValidationEngine, { // remove client-generated tags, which have `id: null`. // Ember Data won't recognize/update them automatically // when returned from the server with ids. + // https://github.com/emberjs/data/issues/1829 updateTags: function () { var tags = this.get('tags'), oldTags = tags.filterBy('id', null); diff --git a/ghost/admin/app/templates/post-settings-menu.hbs b/ghost/admin/app/templates/post-settings-menu.hbs index 147552288d..aa2715d05c 100644 --- a/ghost/admin/app/templates/post-settings-menu.hbs +++ b/ghost/admin/app/templates/post-settings-menu.hbs @@ -40,7 +40,7 @@ multiple=true selection=model.tags content=availableTags - optionValuePath="content.name" + optionValuePath="content.uuid" optionLabelPath="content.name" create-item="addTag" remove-item="removeTag"}}