sergeyt / meteor-typeahead

Autocomplete package for meteor powered by twitter typeahead.js
https://atmospherejs.com/sergeyt/typeahead
MIT License
146 stars 82 forks source link

Unique assign data-source values. #145

Open logicerpsolution opened 8 years ago

logicerpsolution commented 8 years ago

Hi Support, I have some issue . I am creating control like set relationship between the entities. I have also attached the screenshot about control. In this control user select Foreign Entity after selection Foreign Attribute fill behalf of FE.

Problem : The problem is that user can select multiple FE and behalf of these FA will fill. But FA need unique behalf of FE. As you know we can only set single data-source. It contain last collection for all FA. Below is my code. Please give me solution to resolve this issue ASAP. I will very thankful to you do the same. I hope you will give best solution.

Meteor Template Code (TablesPopup)

{{#with JoinLoop}} {{#each this}} ```
{{#if IsMultipleJoinRow}}
{{/if}} {{/each}} {{/with}}

========================TablesPopup===========================

Template.SalesForceTablesPopup.helpers({

Secondarysfobjects: function () {return Session.get("Secondarysfobjects");}


   , Primarysfobjects: function () {return Session.get("Primarysfobjects");}
   , GetSaleForceTablesName: function () {return Session.get("GetSaleForceTableName");}
   , GetSaleForceTablesFields: function () {
       return Session.get("GetSaleForceTableFields");
   }
   , SelectedSalesForceTablesFields: function () {return  Session.get("GetSaleForceTableFields").fields;}
   , JoinLoop: function () {
       debugger;
       var joinedRows = Template.instance().JoinLoop.get();
       var lastRow = joinedRows[joinedRows.length - 1];
       setTimeout(function () {
           Meteor.typeahead.inject("#Attribute" + lastRow);
           Meteor.typeahead.inject("#ForeignEntity" + lastRow);
           Meteor.typeahead.inject("#ForeignAttributeKey" + lastRow);
       }, 3000)
       return joinedRows;
   }
   , IsMultipleJoinRow: function () {
      return Template.instance().JoinLoop.get().length > 1;
   }
   , SalesForceTables: function () {
       return Session.get("GetSaleForceTableName").map(function (key, index) {
           return { "name": key.name, "tableId": key._id };
       });
   }
   , SfTablesForeignAtt: function () {
       var _CurrentOptions = Session.get("CurrentOptions");
       var currentObjects = Session.get("SfTablesForeignAtt") || {};
       if (typeof _CurrentOptions != "undefined") {
           setTimeout(function () {
               Meteor.typeahead.inject("#" + _CurrentOptions.ForeignAttributeId);
           }, 3000);
            return currentObjects[_CurrentOptions.TableName];
         //  return currentObjects;
       } else {
           return currentObjects;
       }

   }
   , selected: function (event, suggestion, datasetName) {
       if (event.target.dataset.key == "ForeignEntity") {
           var array = Session.get("SfTablesForeignAtt") || {};
           array.randomno = Random.id(10);
           if (typeof array[suggestion.name] == "undefined") {
               app.sf().GetSalesForceLocalTableFields(suggestion.tableId, function (data, status) {
                   if (status) {
                       array[suggestion.name] = data.fields.map(function (key, index) {
                           return { "name": key.name, "tableId": key._id };
                       });
                       Session.set("SfTablesForeignAtt", array);
                       Session.set("CurrentOptions", { "ForeignAttributeId": event.target.dataset.relationalid, "TableName": suggestion.name });
                   }
               });
           }
           Session.set("SfTablesForeignAtt", array);
           Session.set("CurrentOptions", { "ForeignAttributeId": event.target.dataset.relationalid, "TableName": suggestion.name });
       }
   }
})

Template.SalesForceTablesPopup.onRendered(function () {
  //  Meteor.typeahead.inject();
})

Template.SalesForceTablesPopup.onCreated(function () {
     var _self = this;
     var defaultValue = [];
     defaultValue.push(1);
     _self.JoinLoop = new ReactiveVar([]);
     _self.CurrentOptions = new ReactiveVar();

_self.JoinLoop.set(defaultValue);



})

![screenshot_1](https://cloud.githubusercontent.com/assets/6712186/14041970/b3ddd41a-f29b-11e5-8de1-cf9ddda5e1ca.png)