Clearing uikit html editor

669 Views Asked by At

i am trying to clear the content of my uikit html editor after saving data of when closing/cancelling my modal.

i tried clearing it with these codes:

 $("#description").val('');
 $('#description').attr('data-uk-htmleditor');
 $.UIkit.htmleditor('#description', { /* options */ });

but it's still not working. does anyone here can help me? EDIT:

here's my other codes for pulling the data from the database:

function editTask(id){
key = id;
s_type = 'u';
console.log(s_type);
enableForm('#task');

$('#btn-save-task').hide();
$('#btn-save-edited-task,#btn-cancel-task').show();
 $.ajax({
        type: "GET",
        url:  baseUrl+"/opportunities/getInfo/task/"+id,
        async    : true,
        data : {

            getType : "getTask"

                },
        dataType: 'json',
        error : function(req,error){
            notify(req.statusText,'warning');
        },
        success: function(data){
                    $("#taskDescription").val(data.description);
                    $('#taskDescription').attr('data-uk-htmleditor');
                    $.UIkit.htmleditor('#taskDescription', { /* options */ });

        }
    }); 

}

1

There are 1 best solutions below

3
On

Try this:

var task = '';
function editTask(id) {
    key = id;
    s_type = 'u';
    console.log(s_type);
    enableForm('#task');

    $('#btn-save-task').hide();
    $('#btn-save-edited-task,#btn-cancel-task').show();
    $.ajax({
        type: "GET",
        url: baseUrl + "/opportunities/getInfo/task/" + id,
        async: true,
        data: {

            getType: "getTask"

        },
        dataType: 'json',
        error: function(req, error) {
            notify(req.statusText, 'warning');
        },
        success: function(data) {
            task = data.description;
        }
    });
}

$.UIkit.htmleditor('#taskDescription', { /* options */ });

//Get a reference to the CodeMirror editor
var editor = $('.CodeMirror')[0].CodeMirror;

//You can then use it as you wish
editor.setValue(task);