refactory-id / bootstrap-markdown

Bootstrap plugin for markdown editing
Apache License 2.0
1.99k stars 371 forks source link

Changes made using the editor buttons doesn't trigger onchange on the textarea #308

Closed BudgieInWA closed 4 years ago

BudgieInWA commented 6 years ago

To reproduce follow these steps:

  1. Browse to the demo page at http://www.codingdrama.com/bootstrap-markdown/, or any other instance of the editor.
  2. Set up logging of the onchange events for the textarea by executing the following in the browser console. This selects the first textarea in the demo page at the time of writing. $('textarea[name=content]').change(console.log.bind(console))
  3. Edit the content inside the textarea and then blur the textarea. Notice that the onchange event was logged to the console.
  4. Now select some text and make it bold using the editor button and blur the textarea before making any other changes. Notice that no onchange event was triggered.

An onchange event should be triggered in this case.

eric-hemasystems commented 4 years ago

I had the same problem. A change may not be captured because a button did not trigger the change event. I found the following in the code:

// Trigger onChange for each button handle
this.change(this);

I'm not very good with jQuery but I think there may be two problems with this:

  1. The argument given to change may trigger event registration instead of event triggering. According to the docs no argument should be given to trigger events.
  2. I think this is the container for the markdown field. In general I think this is the textarea element but there is also some sort of inline editing support. In that case maybe it isn't?. Other code seems to refer to this.$textarea to explicitly target the textarea (which I think is what we want).

Given those two issues I change the code to:

this.$textarea.change();

Interactive testing seemed to show that this works.

lodev09 commented 4 years ago

this is the instance of the Markdown object itself -- not the Texarea element. @eric-hemasystems is correct, use this.$textarea as this holds the element itself.

BudgieInWA commented 4 years ago

@lodev09 the bug that you have confirmed in your comment exists within this repo, it is not something that users of this library can change. Can this issue be re-opened until the fix is merged?