Guest User

Untitled

a guest
Jan 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Init variable
  2. var ids =[];
  3. var selected_values = [];
  4. var updated_data = [];
  5. var collect_data = [];
  6. var salesforce_element;
  7. //Collect ids of Salesforce lookup inner element.
  8. $( document ).on( "click", ".formyoula-Salesforce", function(){
  9. //Replace the value 2- :lt(2) based on pre-filled lookup element.
  10. salesforce_element = $(this);
  11.  
  12. })
  13. //Script for list of result on lookup.
  14. $( document ).on( "click", "li.select_salesforce_record", function() {
  15. ids = [];
  16. $("#component-c7f0-50c5-1f15 .input_content").first().trigger("change");
  17. var repeat_group_index = salesforce_element.parent().parent().parent().parent()[0].id.split("_")[2];
  18. salesforce_element.nextAll(':lt(3)').each(function(index,component){
  19. //Collecting the ids.
  20. ids.push(component.id.split("component-")[1]);
  21. })
  22. selected_values = [];
  23. //Get all childern element
  24. var elements = $(this).children();
  25. //Loop for collecting the values
  26. for(var i = 0; i < elements.length; i++) {
  27. //Set the current element.
  28. var current = elements[i];
  29. if(current.textContent.replace(/ |\n/g,'') !== '') {
  30. //Get and add the selected value.
  31. selected_values.push(current.textContent);
  32. }
  33. }
  34.  
  35. //Loop to assing the values.
  36. for(var index=0; index < ids.length; index++){
  37. //Set the component value on UI
  38. $("#component-"+ids[index]+" input").val(selected_values[index])
  39. //Set data to formyoula form fields
  40. var repeat_data = window.formyoula.form_fields["c7f0-50c5-1f15"].get("repeat_value");
  41. for(var repeat_index=0; repeat_index<repeat_data.length; repeat_index++ ) {
  42. for(var component_index=0; component_index<repeat_data[repeat_index].length; component_index++) {
  43. var component_id = window.formyoula.form_fields["c7f0-50c5-1f15"].get("repeat_value")[repeat_index][component_index].component_id;
  44. if (ids[index] == component_id) {
  45. //Condition for the product name UI and product name for hidden field.
  46. var selected_value = index == 0 ? selected_values[index] : selected_values[index-1];
  47. collect_data.push({repeat_index: repeat_group_index,component_id: component_id,value: selected_value});
  48. }
  49. }
  50. }
  51. }
  52. })
Add Comment
Please, Sign In to add comment