Saved messages as HTML
I'm wondering, on your episode https://gorails.com/episodes/message-templates, would it be possible to have one of the saved messages as HTML? I've tried entering
<h1>test</h1><p>this is a test</p> but nothing appears once selected (just some whitespace). Plain text works fine.
This is what I see in the source:
<option data-body="<h1>test</h1><br><p>this is a test</p>" value="1">Test</option>
It's obviously formatting it, but am I able to disable this?
Thanks Chris, I appreciate it.
This is actually a small bug you find in the JS for that episode. The
handleChange works fine for adding plain strings, but not HTML ones to the value of the inputs. If you change the append line to the following, you'll see that it works just fine:
comment_body.val comment_body.val() + saved_message_text
This is a better way of adding text to a field, where you set the value to the old value plus your new text. Append seems to do that, but not when there is html that you want to add for some reason.
I updated the repository to fix that bug as well. 👍
That's brilliant Chris, works perfectly! :) Thanks very much. Been playing around with it all night but I'm quite the novice when it comes to JS!
Yeah, that was one of those weird things that jQuery does. It'll work as you might think, but not completely. If you were writing this with plain JS, you'd use the same code as I did in my solution basically. No funny business that way.