+ Start a Discussion
tyshocktyshock 

Question on AJAX auto-binding

I'm finding the current implementation of auto-binding limited if I have > 1 dynabean of the same type that I would like to bind.  For example, if I have 2 Accounts, and 2 fields with ("afBind"="name=FirstName"), then there is no way to reliably auto-bind the 2nd bean, as it would just pick up the same form element that the first bean picked up.  The easy way to solve this is to allow an optional variable such as 'autobindAttr' which will allow you to define the custom autobind attribute name on the bind() call.
 
For example:
 
account1.bind("afBind");
account2.bind("myBind");
etc..........
 
Am I missing another easier way to handle this dilemma?
 
Thanks.
 
 
DevAngelDevAngel

Hi tyshock,

Yes, I think doing what suggest should work.  Why not give it a try?  Add this code to you html and give it a shot.

Code:

Sforce.Dynabean.prototype.bind = function(bindingAttrId) {
 /** @private */var nodes = Sforce.doc.childNodes;
 /** @private */var _this = this;
 /** @private */Sforce.win.db = this;
 
 this.bindNodes = function(nodes) {
  for (var i=0;i<nodes.length;i++) {
   if (nodes[i].getAttribute(bindingAttrId) != undefined) {
    _this.bindField(nodes[i], nodes[i].getAttribute(bindingAttrId));
   }
  }
 };
 this.bindSelects = function() {var n = Sforce.doc.getElementsByTagName("select");this.bindNodes(n);};
 this.bindInputs = function() { var n = Sforce.doc.getElementsByTagName("input");this.bindNodes(n);};
 this.bindTextAreas  = function() {var n = Sforce.doc.getElementsByTagName("textarea");this.bindNodes(n);};  
 
 this.bindTextAreas();
 this.bindInputs();
 this.bindSelects();
 
};