Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to get the content of a <textarea> element

Post Reply
CarlosFeitozaFilho
Posts: 3
Joined: Wed Nov 17, 2021 6:40 pm

How to get the content of a <textarea> element

Post by CarlosFeitozaFilho »

I'm developing a Delphi program where I display TinyMCE on a screen and I need to get the content that the user edited, in Delphi. This sounds simple enough, I just get the content of the <textarea> element to which TinyMCE was applied.

To achieve this, in the callback I called "OnVisitDom" (which is passed to the AFrame.VisitDom method in OnProcessMessageReceived), I just do ADocument.GetElementById('content').GetValue, but I don't get any content!

The question then is simple: how do I get the content of a <textarea> so that I can use it on the Delphi side?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get the content of a <textarea> element

Post by salvadordf »

Hi,

The DOMVisitor demo shows how to get the element value. It's recommended to execute JavaScript to get that value because the DOM features in CEF are not as powerful as the JavaScript ones.

These are the code comments inside the "SimpleNodeSearch" function :

Code: Select all

            // Here we send the name and value of the element with the "console trick".
            // The name and value contents are included in TempMessage and the we
            // execute "console.log" in JavaScript to send TempMessage with a
            // known preamble that will be used to identify the message in the
            // TChromium.OnConsoleMessage event.

            // NOTE : In case you try to read or write node values using the CEF API
            // you should know that ICefDomNode.GetValue and ICefDomNode.SetValue
            // only work in text nodes. ICefDomNode.GetElementAttribute returns
            // the attribute value specified in the HTML and not the current value.

            // It's recommended that you use JavaScript or DevTools methods if
            // you need to get or set the value of HTML elements.
            // For example, if you want to use the "console trick" and you want
            // to get the value of the search box in our forum you would have to
            // execute this JavaScript code :
            // console.log("DOMVISITOR" + document.getElementById("keywords").value);
CarlosFeitozaFilho
Posts: 3
Joined: Wed Nov 17, 2021 6:40 pm

Re: How to get the content of a <textarea> element

Post by CarlosFeitozaFilho »

Hi! Thanks for the answer!

So the only way I can get the dynamic value of the elements is to make use of this device using the JavaScript Console? I have to admit this is VERY disappointing :(

Well, I managed to get the value of some form elements using GetValue, but that doesn't work with <textarea>.

I would really like to have a control like TWebBrowser, but using modern web technologies and that I could install it on my Delphi Rio :(
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get the content of a <textarea> element

Post by salvadordf »

The "console trick" is just a easier way to get the results.

You can also register a JavaScript extension as you can see in the JSRTTIExtension and JSExtension demos to avoid using the console.
CarlosFeitozaFilho
Posts: 3
Joined: Wed Nov 17, 2021 6:40 pm

Re: How to get the content of a <textarea> element

Post by CarlosFeitozaFilho »

salvadordf wrote: Thu Nov 18, 2021 3:44 pm The "console trick" is just a easier way to get the results.

You can also register a JavaScript extension as you can see in the JSRTTIExtension and JSExtension demos to avoid using the console.
I will see this, thank you!
Post Reply