altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

RmlElement is missing TextNode methods.

Open Yiin opened this issue 2 years ago • 2 comments

Description of the problem

There doesn't seem to be a method for getting and setting value of the Text on text node created using document.createTextNode.

Reproduction steps

const document = new alt.RmlDocument("foo.rml");

const fooText = document.createTextNode("foo");

if (fooText.innerRML !== "foo") {
  fooText.innerRML = "foo";
}

document.body.appendChild(fooText);
<rml>
  <head>
    <title>Testing RML</title>
  </head>
  <body></body>
</rml>

Expected behaviour

fooText.innerRML to have value "foo" after creating text node, but it's empty instead. When setting fooText.innerRML to "foo", the game displays duplicated values. e.g. text node was created with value "bar" and has it's innerRML set to "bar" as well.

image

Additional context

Topic in #scripting-questions: https://discord.com/channels/371265202378899476/1128207399774339093

  • Both document.createElement and document.createTextNode returns RmlElement object.
  • RmlUi docs seems to have set/get text methods for TextNode.
  • They're not present on RmlElement.

Operating system

N/A

Version

15.0-dev346

Crashdump ID

No response

Reproduction tested

  • [X] I confirm that I have made sure that this issue is also present on the newest dev version

Yiin avatar Jul 11 '23 07:07 Yiin

Closing this issue because it's unlikely to be fixed and good enough workarounds exist.

The one I use, is setting text value to the RmlElement meta, so I can access it later:

function createTextNode(document: alt.RmlDocument, text: string) {
  const node = document.createTextNode(text);
  node.meta.text = text;
  return node;
}

Yiin avatar Feb 24 '24 15:02 Yiin

I don't see why this wouldn't be fixed, the element is just a Rml::ElementText which has GetText and SetText methods which can be easily exposed to the API.

LeonMrBonnie avatar Feb 24 '24 23:02 LeonMrBonnie