最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - bootstrap wysihtml5 set Value not working - Stack Overflow

programmeradmin0浏览0评论

I have a wysihtml box and I want to fill its value after an ajax call

$("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5();

function ModificaCategoria(id) {
    $.ajax({
                url: "Categorie.aspx/GetCategoria",
                type: 'POST',
                dataType: "json",
                data: JSON.stringify({ 'id': id }),
                contentType: 'application/json; charset=utf-8',
                cache: false,
                async: false,
                processdata: true,
                traditional: true,
                success: function (data) {
                    var c = data.d;
                        //we need to parse it to JSON 
                        c = $.parseJSON(c);
                        $('#<%=txtTitleCategoria.ClientID%>').val(c.Title);
                        $('#<%=txtDescrizioneBreveCategoria.ClientID%>').val(c.Descrizione);
                }
        });
}

I already tried with

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').contents().find('body').html('<b>New text</a>');

and with

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').html(c.Descrizione);

and with

var editorObj = $("#<%=txtDescrizioneBreveCategoria.ClientID%>").data('wysihtml5');
var editor = editorObj.editor;
editor.setValue(c.DescrizioneBreve);

but editor variable is always undefined I'm using wysihtml5x v0.4.15 link here

I have a wysihtml box and I want to fill its value after an ajax call

$("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5();

function ModificaCategoria(id) {
    $.ajax({
                url: "Categorie.aspx/GetCategoria",
                type: 'POST',
                dataType: "json",
                data: JSON.stringify({ 'id': id }),
                contentType: 'application/json; charset=utf-8',
                cache: false,
                async: false,
                processdata: true,
                traditional: true,
                success: function (data) {
                    var c = data.d;
                        //we need to parse it to JSON 
                        c = $.parseJSON(c);
                        $('#<%=txtTitleCategoria.ClientID%>').val(c.Title);
                        $('#<%=txtDescrizioneBreveCategoria.ClientID%>').val(c.Descrizione);
                }
        });
}

I already tried with

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').contents().find('body').html('<b>New text</a>');

and with

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').html(c.Descrizione);

and with

var editorObj = $("#<%=txtDescrizioneBreveCategoria.ClientID%>").data('wysihtml5');
var editor = editorObj.editor;
editor.setValue(c.DescrizioneBreve);

but editor variable is always undefined I'm using wysihtml5x v0.4.15 link here

Share Improve this question edited May 4, 2018 at 7:22 Martina asked May 3, 2018 at 15:58 MartinaMartina 1,9188 gold badges44 silver badges82 bronze badges 5
  • What does the $("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5(); return you? I think that should return you the editor object – Tarun Lalwani Commented May 6, 2018 at 20:08
  • @TarunLalwani yes, but it adds me 2 toolbars. I have one toolbar foreach time I call wysihtml5(). – Martina Commented May 7, 2018 at 8:58
  • You should call it once only and then store the return value and use it. These methods are initialization methods and then you can store the output value in some variable and use it later – Tarun Lalwani Commented May 7, 2018 at 9:02
  • @TarunLalwani You're right! but how can I set the value to the object? I tryied with val("xxx") but not working.. – Martina Commented May 7, 2018 at 9:12
  • Can you create JSfiddle or StackBlitz for me to try the same? – Tarun Lalwani Commented May 7, 2018 at 9:15
Add a ment  | 

4 Answers 4

Reset to default 4 +50

You should be able to achieve the same using below

$("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5();
window.describeEditor = window.editor;

And then later you should can use

describeEditor.setValue(c.DescrizioneBreve, true)

or use

editorDescrizioneBreve.data("wysihtml5").editor.setValue(c.DescrizioneBreve, true);

Where editorDescrizioneBreve is the object returned by $("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5()

PS: Solution based on https://github./jhollingworth/bootstrap-wysihtml5/issues/52

For me, this worked:

$('.wysihtml5-sandbox').contents().find('body').html(descr)

I have only one Wysihtml5 on my page, with multiple, you need to use more precise selector.

Below code works for me

<textarea class="wysihtml5 form-control" rows="15"  id="txtContent" runat="server"></textarea>

   <script type="text/javascript"> 
      function GetContent() {
      var evnt = {RECORD_ID:'101'};
      $.ajax({
               type: "post",
               url: '/API/GetContent',
               contentType: "application/json; charset=utf-8",
               data: JSON.stringify(evnt),
               success: function (result) {
                  if (result) {             
                      var editorObj = $("#<%=txtContent.ClientID%>").data('wysihtml5');
                      var editor = editorObj.editor;
                      editor.setValue(result.CONTENT);
                  }
              }
          });
           }
    </script>

For my work that:

$('#ID OF ELEMENT').data("wysihtml5").editor.setValue('TEXT TO INSERT');

And i have some in the same page. :D

For more information: https://github./jhollingworth/bootstrap-wysihtml5/issues/52

发布评论

评论列表(0)

  1. 暂无评论