Set value in the textarea (Tinymce) by clicking on the table line

Asked

Viewed 38 times

0

Come on, guys, I need a little help here... I am using the Tinymce plugin in a textarea element of my application Node.JS, I wanted to know how to set a text in this element, this text is coming from a Mysql foreach where when clicking the edit button of the row of my table makes a set value in the modal elements, below reference excerpt:

<td>
<button class="btn btn-xs btn-warning" data-toggle="modal" data-target="#modalEdit" onclick="(function(){

   //Setando o valor nos campos de texto
   document.getElementById('cod_Section9Sub_Alterar').value = '<%= row.cod %>';
   document.getElementById('autor_Section9Sub_Alterar').value = '<%= row.autor %>';
   document.getElementById('titulo_Section9Sub_Alterar').value = '<%= row.titulo %>';
   document.getElementById('artigo_Section9Sub_Alterar').value = '<%= row.artigo %>';//Ajuda aqui

})()">

Editar</button>
</td>

And here is the excerpt from my textarea element that is within the so-called modal:

<!-- Artigo -->
<div class="row">
 <div class="col-sm-12">
  <div class="form-group">
   <label for="artigo_Section9Sub_Alterar" class="label">Sua postagem</label>
    <textarea class="form-control" name="artigo_Section9Sub_Alterar"
    id="artigo_Section9Sub_Alterar" placeholder="Sua postagem" rows="10 auto"
    required></textarea>
   </div>
  </div>
</div>

If I remove the set value line of the textarea everything works perfectly, if I return this excerpt leaves popular the modal.

I’ve tried the option: tinymce.get('#artigo_Section9Sub_Alterar').setContent('<%= row.artigo %>'); and also did not happen.

  • Try it this way: document.getElementById("artigo_Section9Sub_Alterar_ifr").contentDocument.querySelector("body").innerHTML = "<%= row.artigo %>";. Depending on what comes in <%= row.artigo %>, this is not the ideal way to do it.

  • It worked Sam, but adding window.Parent looks: window.parent.tinymce.get('artigo_Section9Sub_Alterar'). getBody(). innerHTML = '<%= Row.article %>'; Thank you very much! Please add as an answer to the question so I can mark as a solution.

  • Cool. No window.Parent does not work?

  • No, without it it didn’t work.

  • Only window should work too, because Parent takes the parent window, and if you are already in the parent window it is redundant to use Parent. But it is still at the end.

  • true, only with window worked, Sam if you can help me with one more question I’d like to thank: https://answall.com/questions/456168/display-texto-do-bd-numa-div-considerando-as-tags-html-contidas-neste-text

Show 1 more comment

1 answer

0

With the help of our colleague Sam, problem solved.

Solution: window.parent.tinymce.get('artigo_Section9Sub_Alterar').getBody().innerHTML = '<%= row.artigo %>';

Browser other questions tagged

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