Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Init variable
- var ids =[];
- var selected_values = [];
- var updated_data = [];
- var collect_data = [];
- var salesforce_element;
- //Collect ids of Salesforce lookup inner element.
- $( document ).on( "click", ".formyoula-Salesforce", function(){
- //Replace the value 2- :lt(2) based on pre-filled lookup element.
- salesforce_element = $(this);
- })
- //Script for list of result on lookup.
- $( document ).on( "click", "li.select_salesforce_record", function() {
- ids = [];
- $("#component-c7f0-50c5-1f15 .input_content").first().trigger("change");
- var repeat_group_index = salesforce_element.parent().parent().parent().parent()[0].id.split("_")[2];
- salesforce_element.nextAll(':lt(3)').each(function(index,component){
- //Collecting the ids.
- ids.push(component.id.split("component-")[1]);
- })
- selected_values = [];
- //Get all childern element
- var elements = $(this).children();
- //Loop for collecting the values
- for(var i = 0; i < elements.length; i++) {
- //Set the current element.
- var current = elements[i];
- if(current.textContent.replace(/ |\n/g,'') !== '') {
- //Get and add the selected value.
- selected_values.push(current.textContent);
- }
- }
- //Loop to assing the values.
- for(var index=0; index < ids.length; index++){
- //Set the component value on UI
- $("#component-"+ids[index]+" input").val(selected_values[index])
- //Set data to formyoula form fields
- var repeat_data = window.formyoula.form_fields["c7f0-50c5-1f15"].get("repeat_value");
- for(var repeat_index=0; repeat_index<repeat_data.length; repeat_index++ ) {
- for(var component_index=0; component_index<repeat_data[repeat_index].length; component_index++) {
- var component_id = window.formyoula.form_fields["c7f0-50c5-1f15"].get("repeat_value")[repeat_index][component_index].component_id;
- if (ids[index] == component_id) {
- //Condition for the product name UI and product name for hidden field.
- var selected_value = index == 0 ? selected_values[index] : selected_values[index-1];
- collect_data.push({repeat_index: repeat_group_index,component_id: component_id,value: selected_value});
- }
- }
- }
- }
- })
Add Comment
Please, Sign In to add comment