Passing Data to Page from Reusable Element in Repeating Group - Seeking Optimal Solution šŸ˜•

Hi everyone,

I hope you are doing well. Iā€™ve been working on a project recently and encountered a challenge that I need your help with. I have a reusable element in my app that I want to use within a repeating group, and I need to pass data from this reusable element to the page it resides in.

Iā€™ve spent a considerable amount of time researching and experimenting with various solutions. I tried using the "Satellite " plugin, but unfortunately, it didnā€™t work as expected with repeating groups, and I encountered numerous bugs. Iā€™ve also tested several other scenarios, but each one seems to have issues when dealing with repeating groups.

To give you a better idea, here are some of the challenges and scenarios I encountered:

  1. Satellite Plugin: I tried using the "Satellite " plugin, but it didnā€™t work well with repeating groups, and I faced issues with data synchronization and handling events.
  2. Passing Data: I attempted to pass data using custom states, but this resulted in inconsistency and difficulties when updating the elements within the repeating group.
  3. Workarounds: I even tried various workarounds like using URL parameters and using unique IDs for each element, but these approaches proved to be error-prone and inefficient.

Iā€™m reaching out to you all because I believe there must be an optimal solution or best practice to handle this situation efficiently. Iā€™m looking for suggestions, ideas, or any insights on how to pass data from a reusable element within a repeating group effectively.

If any of you have faced similar challenges or have experience in dealing with this kind of scenario, Iā€™d greatly appreciate your guidance. I want to find the best approach to handle this problem in the most time-efficient manner.

Thank you all for your time and expertise. Iā€™m eager to hear your thoughts and recommendations.

Best regards, amer

2 Likes

Personally, I think the simplest way to do this type of thing is just with a JavaScript to Bubble element. Itā€™s how I do it.

Put the JavaScript to Bubble element on the page, set it to publish a value of the relevant type, then in the RE just use a run JavaScript action to call the element as a function and pass the relevant data into it.

7 Likes

Thank you @adamhholmes for your suggestion! I appreciate your insight on using JavaScript to Bubble elements. Iā€™ll definitely give it a try and implement your approach. Grateful for your help!

2 Likes

I am encountering this issue too and it seems like your solution may work. I donā€™t know too much about javascript - any chance you have an example you could share so I can see how this works?

@calicass83 Sureā€¦

Hereā€™s a simple example of passing a value from a nested Reusable Element to a JavaScript To Bubble element on the main page, avoiding the need to use custom states and only when conditions through multiple layers of nesting, or an additional plugins.

Just have the JS to Bubble element on the page, and in the nested RE run a Javascript action to call the function and pass the relevant data to it.

Data From RE With JavaScript (bubbleapps.io)

2 Likes

There are one or two pages in that app :stuck_out_tongue:

1 Like

Thank you for this solution, itā€™s excellent! I was going crazy with all the custom states and only-when workflows.

1 Like

Would this // how would this work in reverse?

Is that possible? Trying to pass data from the main page, to a reusable that sits inside of a repeating group?

Should work just the sameā€¦ (as long as each instance of the JavaScript to bubble element has a unique function name)

@adamhholmes

Hi Adam:

Iā€™ve followed the instructions and checked the editor - Iā€™m sure I must be missing.

Iā€™ve put a reusable element in a repeating group and I have a run javascript with the below

RE run javascript

In the main app, Iā€™ve done this:

Iā€™ve gone over it several times but I cannot seem to get a value from the javascript to bubble function.

May I kindly ask for your comment? I appreciate any hint you may be able to give me as to where I should focus my effort.

To add, this is the only Javascript to Bubble function that I have in the entire app.

Hi Adam

I poked around the editor and found another example of using the JS to Bubble element with reusables, but this one put out a JSON formatted text.

];

let rgValues = [];

rgItems.forEach(item => {
  let inputID = `rgInput${item}`;
  let inputElement = document.getElementById(inputID);
  let itemObject = { itemNumber: item, itemValue: inputElement.value };
  rgValues.push(itemObject);
});

console.log(rgValues);

let rgJSON = JSON.stringify(rgValues, null, 2);

bubble_fn_rgJSON(rgJSON);

When using it I see that all values expressed in the JSON are enclosed with quotation marks indicating a text value.

Screen Shot 2024-08-18 at 4.50.54 PM

Except the Number for the itemNumber key.

I do not know much of anything about javascript, but when I try to figure out how to make it so that the quotation marks appear only for a text value, while leaving numerical values without quotation marks, I can not find anything in the javascript that makes the quotation marks enclose the values.

I tried to remove the ā€˜ā€™ that enclose the rgInput${item} portion, but that causes the javascript to not run.

Is there a way to alter the javascript so that the quotation marks do not appear?

Iā€™ve been successful in getting this to work for my use case which takes values from multiple input elements within the RG, but for the JSON formatting to use quotation marks only around text values, I can not find a way to make that change.

This is correct JSON formatting.

In JSON Keys are enclosed in double quotes.

Yes, I was asking about the values associated with the keys. The javascript makes it such that all values are in double quotes, whether they are for a number or a word. I was curious if you knew how to modify the code so that not all values are in double quotes, so if I have a Key of ā€œWordā€ and a key of ā€œNumberā€ the values for ā€œWordā€ key pairs would be in double quotes but for the values of key pairs for ā€œNumberā€ keys they would not be in double quotes.

Screen Shot 2024-08-18 at 9.33.20 PM

Right now using the code, I get all values in double quotes, but for something like ā€œweightā€ value I would need no double quotes as it is a number, but for ā€œweight_optionā€ I would need double quotes as it is a word.

Ah, okā€¦ I understand what youā€™re sayingā€¦

The value of an input element is always a string, regardless of the ā€˜typeā€™ of the input. (Bubble automatically converts the value to the type defined in the input settings, but the actual value of the html element will remain a string).

So youā€™ll need to convert the relevant values to numbers in your code.

Unlike standard HTML inputs (which can have a ā€˜typeā€™ - even though they always output strings), Bubble input elements are always of the input type Text - which makes it hard to identify which values should be numbers or texts (as you canā€™t simply check the inputā€™s ā€˜typeā€™).

So you might have to add a class to your input elements (depending on whether they are text or number), and then in your code check for the presence of each class to determine whether to cover the input value to a number.