Expand my Community achievements bar.

SOLVED

Static Text + Prefill

Avatar

Level 1

I am using AEM Form 6.3. Currently, the inputs are pre-filled as described in the article with a JSON schema (Adobe Experience Manager Help | Prefill adaptive form fields ). It all works.

However, I would like to pre-populate a static text as well. The static text component has been set via "Bind Reference" as well. But the value from the incoming JSON was not displayed on it. It only displays the default value of "The text will appear here". I am trying not to use textbox as the static text has the ability to wrap itself with the href attribute, which is required in my use case as well.

Is there a way to get it to display the value from my JSON? Or is there an alternative?

1 Accepted Solution

Avatar

Correct answer by
Level 3

So, I guess final correct answer should be add below mentioned code to code editor on initialize:

guideBridge.on("bridgeInitializeComplete", function (event, data) {

   guideBridge.resolveNode("staticText1").value = "Your new static text here";

});

I have created a blog post which delves into details around how to dynamically change static text

smacdonald2008​ : I think we should change the correct answer, as the answer which is currently marked correct answer, will never work in this question's use-case, Prefill Scenario. It will confuse other readers in its current state.

Cheers,

Jagjeet

AEM Forms Blog

View solution in original post

8 Replies

Avatar

Level 7

You can set the value of the static text from javascript either in the rules editor or a client library referring to it by Element Name e.g.

staticText1.value = "Test text";

You could of course source the text in this example from a JSON object. Does that help?

Also worth noting that the rules editor needs to be in code editor mode, the visual editor doesn't allow you to set the value of static text items.

Avatar

Level 3

Hi fir89/James R Green,

There is another caveat with James answer. I haven't ever been able to get this thing working with initialize of AEM Form (maybe I am missing some trick here). As far as I know, This particular thing only works after the complete DOM is loaded.

Since you want something where the text should be prefilled on load of form, I suppose this won't work. What you will have to do instead is you will have to fire this particular piece of code once the complete form is loaded. You may do this by  adding a listener like

window.addEventListener("bridgeInitializeStart", function(evnt) {
     // get hold of the guideBridge object
     var gb = evnt.detail.guideBridge;

     gb.resolveNode("staticText1").value = "abc";

})

James R Green​ : Please let me know if I am missing a trick and this works on initialize.

Thanks,

Jagjeet Singh

AEM Forms Blog

Avatar

Level 7

Hi @jagjeetthukral

Are you using listening to the bridgeInitializeComplete event?

gb.on("bridgeInitializeComplete", function (event, data) {

    // code here

});

Avatar

Level 3

Yes James. I wanted to write bridgeInitializeComplete.

But the point I wanted to make is, the suggestion you made in the previous comment which says to use  staticText1.value = "Test text"; won't work from initialize script (for prefill) from Form's Rule editor.

PFB The screenshots for the same, static text remains unchanged even after script.

Screen Shot 2018-02-06 at 9.41.30 PM.png

Screen Shot 2018-02-06 at 9.42.04 PM.png

Please let me know, if I am doing something wrong.

My suggestion to the original problem will be to call static Text value change after guideBridge has been completely initialized, which can be written in a client lib file.

Thanks,

Jagjeet

AEM Forms Blog

Avatar

Level 7

Hi jagjeetthukral​,

Right I see - thanks for pointing that out! The test I performed from the rules editor was actually from a button press. Setting from rules editor on init in forms editor doesn't seem to work for static text (unlike for textboxes). So yes to init the static text fields it looks like it needs to be done after guide bridge has initialised or on an event such as a click of a button. Screenshot of my tests below for reference:

init_text.png

Set from rules editor with the name of the fields.value (or this.value) and from clientlib as described by Jagjeet:

gb.on("bridgeInitializeComplete", function (event, data) {

   gb.resolveNode("text4").value = "text4 set from clientlib";

   gb.resolveNode("textbox4").value = "textbox4 set from clientlib";

});

Avatar

Correct answer by
Level 3

So, I guess final correct answer should be add below mentioned code to code editor on initialize:

guideBridge.on("bridgeInitializeComplete", function (event, data) {

   guideBridge.resolveNode("staticText1").value = "Your new static text here";

});

I have created a blog post which delves into details around how to dynamically change static text

smacdonald2008​ : I think we should change the correct answer, as the answer which is currently marked correct answer, will never work in this question's use-case, Prefill Scenario. It will confuse other readers in its current state.

Cheers,

Jagjeet

AEM Forms Blog