Dynamically change binding of field | Community
Skip to main content
October 18, 2007

Dynamically change binding of field

  • October 18, 2007
  • 3 replies
  • 8754 views
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
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

October 24, 2007
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
June 26, 2009

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

June 26, 2009

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

October 24, 2007
Hi Jean,



Yep, that was it. Thanks! :-)



Daniel
March 2, 2009
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.