Skip to main content
Nintex Community Menu Bar
Question

Help accessing the contents of a text component and updating it with a javascript function

  • July 12, 2024
  • 1 reply
  • 1 view

Forum|alt.badge.img+2

Long story short.

I have a page with a text component. This text component has a token, for example, [[token]] (that is not part of a model). That token will refer to an html text that could contain a mustache token such as <p>{{Model.name}} lorem ipsum </p>.

I’m using Javascript (and also tried javascript formula) to reach the [[token]] and then replace by it’s contents.

So goal one would be replace [[token]] with <p>{{Model.name}} lorem ipsum </p>.
Goal 2 would be transforming <p>{{Model.name}} lorem ipsum </p> to something like <p>Jane Doe lorem ipsum </p>.

What I’m doing is using a generic javascript to loop through all page components, identify the type that has that content and then apply the function.

The only issue I’m having is that after I load the component all seems empty or undefined. I attempted various methods from before to get the inner html of that component and apply the function."

This is a snipped of the function.

    // Iterate over all components on the page
    skuid.$.each(page.component.getAll(), function(i, component) {
        // Check if the component is a text component
        if (component.type === 'skuid__text') {
            var cmp = skuid.component.getById([component.id]);
            console.log(cmp);
        }
    });

How can I access the component inner html or input value and update it ?

Translate
Did this topic help you find an answer to your question?

1 reply

Forum|alt.badge.img+2
  • Author
  • 6 replies
  • July 12, 2024

After awhile and with some help I found out how to access the component contents.

cmp.state.contents

and if you need to update

cmp.state.mergedcontents = 'new text';
Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings