Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

nuSetValue in WYSIWYG field Topic is solved

Questions related to using nuBuilder Forte.
Post Reply
yvesf
Posts: 305
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 83 times
Been thanked: 11 times

nuSetValue in WYSIWYG field

Unread post 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
kev1n
nuBuilder Team
Posts: 4242
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 68 times
Been thanked: 422 times
Contact:

Re: nuSetValue in WYSIWYG field

Unread post 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)
kev1n
nuBuilder Team
Posts: 4242
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 68 times
Been thanked: 422 times
Contact:

Re: nuSetValue in WYSIWYG field

Unread post by kev1n »

This is now on GitHub — nuSetValue() also updates the content of a (TinyMCE) editor.
yvesf
Posts: 305
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 83 times
Been thanked: 11 times

Re: nuSetValue in WYSIWYG field

Unread post by yvesf »

thx Kev1n.
Post Reply