WYSIHTML5 - Text area is not being populated by the API

Asked

Viewed 71 times

1

I have a data editing modal with a text area that is populated by API response. It works perfectly - without WYSIHTML5. When active, the textarea does not display the API response. I have tried using other richtext editors, but the same problem happens. Is there any way to make it work/some editor that doesn’t clean the textarea?

The call from 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 on 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>

And the modal:

<div class="modal fade" id="newsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-body">
          ...
          <div class="form-group
            <textarea class="form-control" placeholder="Text" id="textNewsBody" style="height: 300px"></textarea>
          </div>
          ...
        </div>
      </div>
    </div>
  </div>

Thank you in advance!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.