lynnetye / ember-trix-editor

An Ember.js addon that wraps the Trix editor in a component
http://lynnetye.com/ember-trix-editor/
MIT License
35 stars 15 forks source link

Can't set content of the {{trix-editor}} component #7

Open felixkiss opened 8 years ago

felixkiss commented 8 years ago

I use {{trix-editor}} like so:

{{trix-editor value=model.description trix-change=(action "descriptionChanged")}}

When I type something in (e.g. "Foo Bar"), the model.description is set in descriptionChanged.

Now if a new model comes along (initially with an empty description), the trix-editor will still show whatever the user typed in for the old model's description (because value only populates on initial rendering of trix-editor).

this.set('model', this.store.createRecord('invoice'));
// => model.description is now an empty string, but trix-editor still shows "Foo Bar"

How can I clear/set the content of the trix-editor?

dirkdirk commented 7 years ago

@felixkiss, did you ever figure this out?

felixkiss commented 7 years ago

@dirkdirk Right now, you have to do this manually. We do it like so:

// Clear trix-editor content
const trixEditor = document.querySelector('.description trix-editor');
if (trixEditor) {
  trixEditor.editor.loadHTML(this.get('model.description'));
}
dirkdirk commented 7 years ago

@felixkiss, thanks for the quick reply.

I actually switched to Simditor and had a similar problem but was able to solve it. Perhaps my answer there will help y'all.

https://github.com/wecatch/ember-cli-simditor/issues/6