# Set post custom field when composing

**URL:** https://meta.discourse.org/t/set-post-custom-field-when-composing/78642
**Category:** Development
**Created:** [January 22, 2018, 11:15am UTC](https://meta.discourse.org/t/set-post-custom-field-when-composing/78642 "2018-01-22T11:15:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sicher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sicher/32/120363_2.png) [@sicher](https://meta.discourse.org/u/sicher)
#### Post date: [January 22, 2018, 11:15am UTC](https://meta.discourse.org/t/set-post-custom-field-when-composing/78642/1 "2018-01-22T11:15:18Z")

</div>

I am working on a plugin that should allow users to create specially flagged posts when pressing a button in the topic view. The post flag is just a boolean value. This is for interaction with an external tool. Currently, I have solved the following:

1. I have added a custom action that opens the composer when the user presses the new button. Currently, the action is added by:

```plaintext
  api.modifyClass('controller:topic', {
    actions: {
      postFlagged(post) {
        ...

```

1. I have added a custom field to the Post class and added it to the serializer. The field shows up in the serialized json as expected:

```plaintext
Post.register_custom_field_type('my_flag', :boolean)

add_to_serializer(:post, :my_flag, false) do
    object.custom_fields['my_flag']
end

```

1. I can add a method to the composer and have the value stored for the flag show up via handlebars template:

```plaintext
  api.modifyClass('model:composer', {
    flag: function() {
      return this.get('post.my_flag');
    }.property('post.my_flag'),
  });

```

Now, my problem is that I have no idea how to _set_ my custom field flag in the composer. How do I do that?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 10:52pm UTC](https://meta.discourse.org/t/set-post-custom-field-when-composing/78642/2 "2018-01-22T22:52:08Z")

</div>

I am not sure if we allow shipping this to post creator via the controller even.

This is particularly tricky cause we don’t allow end users to set post custom fields so you would need to introduce some sort of whitelist.

Every way I can think of that involves solving this is either pretty hacky or involves lots of core work.

I think simplest thing you can do for now is an extra http req after the post is saved to your plugin controller to set the field.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [January 23, 2018, 8:19am UTC](https://meta.discourse.org/t/set-post-custom-field-when-composing/78642/3 "2018-01-23T08:19:45Z")

</div>

The simplest thing would be to include an extra tag in the post.

```
<!--MYFLAG-->

```

^ doesn’t even require a plugin; you can use a [tag] if you make a plugin.

---

<div class="post-metadata">

### Author: ![sicher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sicher/32/120363_2.png) [@sicher](https://meta.discourse.org/u/sicher)
#### Post date: [January 23, 2018, 9:00am UTC](https://meta.discourse.org/t/set-post-custom-field-when-composing/78642/4 "2018-01-23T09:00:47Z")

</div>

Yeah, but it would be pretty easy for our users to accidentally delete that from the post, plus the external system will need to scan the body of all posts to find the flag, which I believe will be too inefficient.
