Page 1 of 1

nuSetValue in WYSIWYG field

Posted: Sun Apr 13, 2025 10:25 am
by yvesf
Hello,

I’m trying to assign a simple value to a WYSIWYG field using the following code:

Code: Select all

nuSetValue('pat_cs_cumul', 'test affectation');
The field pat_cs_cumul is a WYSIWYG editor on the patient form. This approach works perfectly for standard textarea fields, but it doesn’t seem to apply the value when used with the WYSIWYG field.

Do you know what needs to be done to make this work with a WYSIWYG editor? It seems that tinyMCE has its own method not compatible with nuSetValue() function.

Many thanks,
Yves

Re: nuSetValue in WYSIWYG field

Posted: Sun Apr 13, 2025 11:08 am
by kev1n
Hi Yves,

Give this a try:

This will set the content when the form loads.

Code: Select all

function nuTinyMCEOnInit(e, editor, id) {

    if (id === 'id_of_your_editor_here') {  // <----------- Insert ID of your (WYSIWYG) editor object
        setTinyMCEContent(id, '<h1>hello</h1>nuBuilder!');
    }

}

function setTinyMCEContent(elementId, html) {

    const tinyMCEId = $(`#${elementId}_parent_container`).find('.nuTinyMCE').attr('id');
    const editor = tinymce.get(tinyMCEId);
    if (editor) {
        editor.setContent(html);
    } 

}
Alternatively, you can call setTinyMCEContent('id_of_your_editor_here', '<h1>Hello</h1>nuBuilder!'); to insert content after the form has been loaded (e.g. on a button click)

Re: nuSetValue in WYSIWYG field

Posted: Mon Apr 14, 2025 9:55 am
by kev1n
This is now on GitHub — nuSetValue() also updates the content of a (TinyMCE) editor.

Re: nuSetValue in WYSIWYG field

Posted: Mon Apr 14, 2025 1:37 pm
by yvesf
thx Kev1n.