You are viewing limited content. For full access, please sign in.

Question

Question

How to bind events to all items in a collection- Forms

asked on September 13, 2017

Hello Team, 

We have collection sets being populated dynamically on form load. In the collections we have controls that have on change event bindings, when we run the form the binding is being applied to the first item in the collection only. Nothing is happening in the subsequent sections. Can you advise on how to bind events to all items? 

Thank you.

0 0

Replies

replied on September 13, 2017

So the first problem is that when the document ready event fires, the lookup events probably haven't fired yet so your code is only finding the control that exists initially.

When rows are added to a collection or table, new DOM elements are created without any custom event handlers you may have added to the pre-existing elements.

The way around this is to bind your events after the lookup event. If the lookup event is the only way to change the number of items in the collection, then this is actually pretty straightforward.

NOTE: The following is based on at least 10.2 Update 1

First, find the id for the field that holds the lookup condition (inspect it in the browser). For example, if the value in Field10 is what triggers the collection population, you would do the following.

$(document).on('onloadlookupfinished',function(event){
  // check to see if the target field's lookup event was fired
  if(event.triggerId == 'Field10'){
      //Bind your events handlers here
  }
}

Basically, what this does is piggyback on the form lookup event so when it completes, it looks to see if the lookup event associated with the "trigger" field fired, and if so, it will bind your event handlers.

If you're populating the collections without a condition/trigger field, then you would use ruleId instead of triggerId, and if the lookup might fire again based on user input, you would use "lookupcomplete" instead of "onloadlookupfinished"

You can find more information about these events here.

Another option would be to monitory for changes in the DOM tree of the collection and fire the event when those are detected, but the lookup events are the better option if you're on a recent version.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.