javascriptjodit

Disable multiple jodit editors


I need to disable couple jodit textareas from particular form. How to access many editors not by unique id to disable them and then enable? Using only unique ids makes impossible to use universal functions.

For regular textareas it would be something like this:

var container = document.getElementById(formname);
var textareas = container.getElementsByTagName('textarea');
for(var i = 0; i < textareas.length; i++){
textareas[i].disabled = true;
//editor.setDisabled(true);
}

editor1 = new Jodit("#editor1", {});
editor2 = new Jodit("#editor2", {});
editor3 = new Jodit("#editor3", {});

I would be grateful for any suggestions.


Solution

  • Got it:

    //continer: modal, form, ...
    //state: true/false
    function Disable(container, state){
        const editors = container.querySelectorAll('.editor');
        const editorsids = Array.from(editors, (ids) => ids.id);
        Object.values(editorsids).forEach(val => {
        Jodit.instances[val].setReadOnly(state);
        //Jodit.instances[val].setDisabled(state);
        });
    }
    

    and

    var editors = [].slice.call(document.querySelectorAll('.editor'));
    editors.forEach(function (textarea) {
    var editor = new Jodit(textarea, {
     
        });
    });