I’m about to create a plugin adding a checkbox to Category settings. All is fine with the field until I uncheck the field. In database I can see that value of custom field is set to “false” but as I reopen category settings the checkbox is now checked although the value is still false. Is there something I’m missing?
Here’s the custom field…
~/bump-topic/assets/javascripts/discourse/pre-initializers/extend-for-bumping.js.es6
import Category from 'discourse/models/category';
import computed from 'ember-addons/ember-computed-decorators';
export default {
name: 'extend-for-bumping',
before: 'inject-discourse-objects',
initialize() {
Category.reopen({
@computed('custom_fields.enable_bump_topic')
enable_bump_topic: {
get(value) {
return value === "true";
},
set(value) {
value = value ? "true" : "false";
this.set("custom_fields.enable_bump_topic", value);
return value;
}
}
});
}
};
And the interface part…
~/bump-topic/assets/javascripts/discourse/templates/connectors/category-custom-settings/bump-topic.hbs
{{#if this.siteSettings.bump_topic_enabled}}
<section class='field'>
<div class="enable-bump-topic">
<label class="checkbox-label">
{{input type="checkbox" checked=category.custom_fields.enable_bump_topic}}
{{i18n 'bump_topic.enable_bump_topic'}}
</label>
</div>
</section>
{{/if}}