# إضافة بيانات "opts" إضافية إلى حدث "DiscourseEvent.on(:post\_created)" من جافا سكريبت؟

**URL:** <https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889>\
**Category:** Development\
**Created:** [9 أبريل 2018، 4:05م UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889 "2018-04-09T16:05:46Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Vespura](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vespura/32/206564_2.png) [@Vespura](https://meta.discourse.org/u/Vespura)\
**Post date:** [11 أبريل 2018، 3:49م UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889/5 "2018-04-11T15:49:59Z")

</div>

> [@angus](#):
>
> ```plaintext
> import Composer from 'discourse/models/composer';
> 
> export default {
> name: 'initializer_name'
> initialize() {
> // this adds your property to the attributes serialized to the server by the createPost method in the composer model
> Composer.serializeOnCreate('your_property');
> 
> withPluginApi('0.8.12', api =&gt; {
> api.modifyClass('model:composer', {
> // set your_property here, or modify the composer controller and set it on the model there instead
> })
> })
> }
> }
> 
> ```

I’ve tried this, but it was not completely successful. I’ll try to explain what I need this for exactly:

I’m making a plugin that will hide the original poster as soon as a post is created, but only if that option is enabled for that specific post. I have added a new button to the editor and that works fine. Toggling that button shows the variable named `hide` being set to true/false correctly, and the code you provided does work and “get” the value correctly.

However, it after pressing the button the variable changes, but the variable in your code does not get updated because it only updates once the editor is re-opened or the post is being edited. So I need a way to check the `hide` boolean variable value when the post is actually “saved” / “created”, allowing me to send that to the plugin.rb. And then in the plugin.rb it will check for that value and if that value is true, it will “hide” the original poster.  
(that hiding the poster part all works if I add a check like this:

```ruby
next unless opts[:raw].to_s.include? "<DontHidePost>"

```

but it doesn’t work when i try to do it like this:

```ruby
next unless opts[:hide_post] == true

```

I hope this makes sense now.

If it helps I can pm you my plugin.rb file and my initializer file?

**Edit: TL;DR:**

- I need the value of the variable/parameter to be “grabbed” and passed on at the very last moment when the post is being saved/created, instead of when the editor is being opened.
- ~~I need to be able to get the value of that variable in the `plugin.rb` file, which currently does not seem to work.~~ The variable is getting passed on, and it’s available in `.on(:post_created)`. It’s just the “old” value from when the editor was openend, not when it was changed after.

I appreciate all the help.

---

_[View the full topic](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889)._
