How do I select the Form's body html element in TMS Web Core?

144 Views Asked by At

In short, I have a form that is named MyForm. Looking at the compiled HTML in the browser, I can see that the form is equal to the body tag. I can prove this by changing the form's color to blue and then I can clearly see the body tag has the background color of blue set on it.

So here's my Delphi code where I am trying to get the form's element and then setting a data attribute for it:

MyForm.element.setAttribute('data-test','form');

This results in an error:

Uncaught TypeError: Cannot read properties of null (reading 'setAttribute') Uncaught TypeError: Cannot read properties of null (reading 'setAttribute')

So it's not finding the element of the form. I can prove this by simply doing a console.log(MyForm.element) and that returns a null.

Doing this same code on any other component works perfectly fine except on the form.

How can I select the form's element (body tag) using Delphi?

1

There are 1 best solutions below

2
Shaun Roselt On BEST ANSWER

I'm not sure why MyForm.element doesn't work. I feel like it should work, but in any case. I found that you can use document.body to get the body tag instead of MyForm.element.

So the code to set a data attribute for the body would be:

document.body.setAttribute('data-test','form');

And that's working fine now.