Search code examples
javascriptjqueryasp.netwysihtml5bootstrap-wysiwyg

bootstrap wysihtml5 set Value not working


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


Solution

  • 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.com/jhollingworth/bootstrap-wysihtml5/issues/52