FIX: improves tag-list setting (#9574)

- Prevents setting to display an empty tag
- Updates dropdown when selecting/removing tag
This commit is contained in:
Joffrey JAFFEUX 2020-04-28 20:05:30 +02:00 committed by GitHub
parent 1e603d7003
commit a8308e73e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View File

@ -1,15 +1,17 @@
import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component";
import { action } from "@ember/object";
export default Component.extend({
@discourseComputed("value")
selectedTags: {
get(value) {
return value.split("|");
},
set(value) {
this.set("value", value.join("|"));
return value;
return value.split("|").filter(Boolean);
}
},
@action
changeSelectedTags(tags) {
this.set("value", tags.join("|"));
}
});

View File

@ -1,3 +1,9 @@
{{tag-chooser tags=selectedTags allowCreate=false}}
{{tag-chooser
tags=selectedTags
onChange=(action "changeSelectedTags")
options=(hash
allowAny=false
)
}}
<div class="desc">{{html-safe setting.description}}</div>
{{setting-validation-message message=validationMessage}}

View File

@ -66,8 +66,12 @@ export default MultiSelectComponent.extend(TagsMixin, {
}),
actions: {
onChange(value) {
this.set("tags", value);
onChange(value, items) {
if (this.attrs.onChange) {
this.attrs.onChange(value, items);
} else {
this.set("tags", value);
}
}
},