I’m working on a plugin that will assign a default tag to new topics created in a category.
The below code “works” if I enter tag names separated by “|”, so “tag1|tag2” works. (I can hardly believe it! But I digress.)
<h3>{{i18n 'topic_default_tag.title'}}</h3>
<section class='field default-tag'>
<div class="default-tag">
<label>
{{input type="list" value=category.custom_fields.default_tag }}
{{popup-input-tip validation=tagValidation}}
{{i18n 'topic_default_tag.default_tag'}}
</label>
</div>
</section>
What I’d like now is to have a proper tag selector rather than an un-validated string. It seems like the below should work:
<h3>{{i18n 'topic_default_tag.title'}}</h3>
<section class='field default-tag'>
<div class="default-tag">
<label>
{{tag-chooser tags=category.custom_fields.default_tag tabindex="4" categoryId=category.id}}
{{popup-input-tip validation=tagValidation}}
{{i18n 'topic_default_tag.default_tag'}}
</label>
</div>
</section>
But it doesn’t. The basis of my problem is that I have nearly zero idea how the magic of those handlebars works. Like I guess that the first section works because it’s magically getting the field name from default-tag
in the <section class='field default-tag'>
, but that was lucky.
When I use the tag-chooser
the tags get passed to Rails as an array, which it throws away before I can make them into a |
-delimited string to stick into the CategoryCustomField. With the {{input type=list...}}
I can enter the |
-delimited string myself and it works just fine. Do I need some kind of Ember magic to conver the array into a string on the Ember side?
Maybe I need to do something like What's the best approach to access category specific settings??
EDIT: To add tags before the webhook gets called, use after_create
rather than DiscourseEvent.on(:post_created)
. Rails mostly makes sense to me now, but Ember, Javascript, and CSS, not so much.