Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 767
Martina Avatar asked May 03 '18 15:05

Martina


2 Answers

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

like image 140
Tarun Lalwani Avatar answered Nov 14 '22 20:11

Tarun Lalwani


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.

like image 35
DaWe Avatar answered Nov 14 '22 21:11

DaWe