Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Dynamically change binding of field

Avatar

Former Community Member
Hello all,



I am attempting to develop a form in which the binding of the fields is not yet known at design time.



What I am trying to do is the following:

In the "initialize" event of the form, I have typed the following:



HEADER.FIELD.bind.ref = "$record.DATA_IN.SUBFORM.DATA[1].NAME";

HEADER.FIELD.bind.match = "dataRef";



"HEADER" is a subform with a text field called "FIELD" in it. What happens is: plain nothing - although there is data in the specified node, the fields remains empty.



If I comment out the two lines and put the "$record.DATA_IN.SUBFORM.DATA[1].NAME" directly to the "binding" property, it works just fine. Setting the default binding to "normal" and trying to set it via code does not...



Any hints? Am I missing some important step?



Thanks

Daniel Sattler
6 Replies

Avatar

Former Community Member
Daniel



Using "HEADER.FIELD.bind.ref" as above will resolve the HEADER object in the generated form since your context is $form. In order to modify binding you need to change it in the template model i.e. $template rather than $form.



So you need something like

$template.MyForm.resolveNode("HEADER").FIELD.bind.ref

to set the template property. Same for the match property.



In addition, having modified the template properties you will need to remerge to pick up the changed properties. This can be done by adding

$form.remerge();

to the form:ready event.



jean

Avatar

Level 1

Hello,

I was trying to utilize the same to dynamically bind a text field of a row in a table. The row has been dynamically created at runtime (using instance manager - that is working). Here is the code I used inside the click event of the button after the row instance is created:

$template.data.resolveNode("relocation.tablesubform.addtable.datarow[1]").country_data.bind.ref

= "$record.COUNTRY.DATA[*].FIELD";

$template.data.resolveNode("relocation.tablesubform.addtable.datarow[1]").country_data.bind.match

= "dataRef";

And the code used in ready form event of the button:

$form.remerge();

But for some reason the text field is not getting bound. Could you please advise?

Thanks

Sachin

Avatar

Level 1

I even tried dynamic binding for a single text field but it dint work

Initialize event of root data:

$template.data.resolveNode("relocation).country.bind.ref = "$record.COUNTRY.DATA[*].FIELD";

$template.data.resolveNode("relocation").country.bind.match

="dataRef";

And the code used in ready form event of data:

$form.remerge();

The text field country still did not get binded to $record.COUNTRY.DATA[*].FIELD. The binding at design time was put to none also tried normal.

I am not able to figure what is wrong. please let me know if i need to do anything else other than this. thanks.

Regards,

Sachin

Avatar

Level 1

I am facing a similar issue as Daniel Sattler, the author of the first post in this thread.

However, in contrast to Daniel, I would like to dynamically change the binding variable (bind.ref) of a subform during runtime based on a "change event" triggered by a single/multiple selection in a list box, contained in a different subform.

To summarise: list box A is part of subform A, during completion of the form, the user selects one or more entries from list box A and triggers a "change event". Based on this event a table, part of subform B, is filled with more or less entries, dependent on the users selection in the list box. The rows in this table are determined by the "bind.ref" value of subform B. That means, dependent on the list box selection "bind.ref" will be assigned with a different array, that is also constructed at runtime.

Before asking for hints to a possible solution, I would like to know whether it is possible in general to change the binding of a subform dynamically (so not in the "initialize event" as in Daniel's case), based on a "change event" triggered by a list box selection?

Best

Ed

Avatar

Former Community Member
Hi Jean,



Yep, that was it. Thanks! :-)



Daniel

Avatar

Former Community Member
Hi all.



I had the same issue but the explanation of Jean indeed does the trick.



However, I want to do the binding completely dynamic on each element with a global script.



My question is, is there a way of getting the link to the $template context from the formfield itself (using $.parent or something like that?)



Thanks in advance,



Andy.