Reputation: 41
I have an "edit modal" with a textarea that is populated by an API response. It works just fine. When I activate WYSIHTML5, the textarea returns empty. I have tried other rich text editors, but all of them don't let the textarea be populated. Is there any way that I can make it work?
Here, I call the API:
$('.btnEditNews').live('click', function () {
var data = new FormData();
var xhr = new XMLHttpRequest();
var jsonResponse;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
jsonResponse = JSON.parse(this.response)['singleNews'];
$('#titleNews').val(jsonResponse.title);
$('#textNewsBody').html(jsonResponse.newsText);
$('#imgNews').attr('src', jsonResponse.file);
}
});
xhr.open("GET", url);
xhr.send(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Calling the WYSIHTML5:
$('#textNewsBody').wysihtml5({
"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
"emphasis": true, //Italics, bold, etc. Default true
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
"html": false, //Button which allows you to edit the generated HTML. Default false
"link": false, //Button to insert a link. Default true
"image": false, //Button to insert an image. Default true,
"color": false //Button to change color of font
});
<script src="lib/js/wysihtml5-0.3.0.js"></script>
Thank you in advance!
Upvotes: 1
Views: 210