hougaard / WYSIWYG-AL

What You See Is What You Get Editor for Dynamics 365 Business Central
22 stars 9 forks source link

Problem with CurrPage.Test.Load #1

Open rvveldhuyzen opened 4 years ago

rvveldhuyzen commented 4 years ago

Hi Erik,

First of all thank you for putting your time and effort in providing this nice example of how to integrate a small HTML Editor into BC!

I have been playing around with it and the example works fine as is. But afterI modified the CurrPage.Test.Load from hardcoded text to a text variable (or a field from a table) like:

        usercontrol("TextEdit"; "TextEditor")
        {
            ApplicationArea = All;
            trigger ControlReady()
            begin
                CurrPage.TextEdit.Init();
                //CurrPage.TextEdit.Load('This is a <strong>BOLD</strong> statement!');
                CurrPage.TextEdit.Load(NewText);  //<< NewText is a global text variable
            end;

the addin crashes with the following error (in Event Viewer):
"message": "Cannot read property 'setData' of undefined",

I have tried to find the cause. The only thing I found Googling around is that it could be a problem with Jquery but I have no idea what to do with this info and if this is true.

I also checked the history of your repository and noticed that you commited a change in the MainScript.js in the function Load: image

After I reverted this change the CurrPage.TextEdit.Load worked fine with text coming from a variable.

Is there something I can do to prevent this error because there must be a good reason you decided to change Editor.setData instead of InputArea.value or was it just for the support of readonly?

Thank you in advance for your answer!

andrewgeer commented 4 years ago

Hi Erik, Again thank you for sharing this, I have also had the issue mentioned above, resolved by also adding back in InputArea.value = data; is this correct ?. Thanks Andrew

fgilsc commented 3 years ago

InputArea.value = data worked for me.

Thanks

averied commented 2 years ago

I think it can also be fixed by setting the value using the OnAfterInit trigger:

usercontrol(Test; Wysiwyg)
                {
                    ApplicationArea = All;
                    trigger ControlReady()
                    begin
                        CurrPage.Test.Init();
                        CurrPage.Test.Load('This is a <strong>BOLD</strong> statement!');
                    end;

                    //>>ADD THIS
                    trigger OnAfterInit()
                    begin
                        CurrPage.Test.Load('This is a <strong>BOLD</strong> statement!');
                    end;
                    //<<ADD THIS

                    trigger SaveRequested(data: Text)
                    begin
                        Message(data);
                    end;
                }

erikk has posted a video on Youtube using this control: https://www.youtube.com/watch?v=GI37tlcrX6Y