Automatically select first row in Repeating Group on page load

The scenario is I have 2 repeating groups - RG-Hazards and RG-Risks. When the page loads RG-Hazards displays one or more hazards (if none are present a popup appears to create one).

For each hazard there is one or more risks in RG-Risks. However I can only get the data in RG-Risks to display when I click a row in RG-Hazards. I want to therefore ‘click’ the first row in RG-Hazards when the page loads.

I have researched the solution and I know it is possible to use custom states but I can’t work out how to get this to work.

Any tips please?

Regards

D

No need to use any custom states here…

Just set the data source of RG Risks to the the data related to the first item in RG Hazards - either refer to the RG’s list of things item #1, or just refer directly to the same datasource you use for RG Hazards, item #1 (or you can use :first item instead)

Create a custom state on the RG-Hazards named ‘selected-hazard’ with an initial value of RG-Hazards’ List of Hazards First Item.

If there is any items in the list at page load it will default to the first item.

Now add a workflow to the RG-Hazards Cell that sets the state to the current rows Hazard.

Now in RG-Risks set a search constraint to the Hazard thing from RG-Hazard’s ‘selected-hazard’ state.

Thanks both.

rgmoffett - I am trying to follow your instructions and so I have created a state associated with RG-Hazards and flagged this as a list. The data source for the hazard is initially empty as data gets passed in from the calling page and the source gets populated by a workflow.

When you say add a workflow to the RG-Hazards Cell that sets the state to the current rows Hazard. how do I do this ? What do I use to trigger this workflow??

Then you say in RG-Risks set a search constraint to the Hazard thing from RG-Hazard’s ‘selected-hazard’ state but will this be allowed if RG-Risks is of type Risk Control and not hazard? This is also populated by a workflow on click of a row in RG Hazards

image

Sorry for the questions !!

Custom states that have a type of a custom datatype can’t have default values, so you’ll need to set the value of the custom state list on pageload, then use a workflow action to display the relevant data in the RG Risks…

But there’s no need to use a custom state at all as I said (you can but it’s making it more complicated that it needs to be - why load the same data again when you’re already loading it into the RG Hazards?)

So you can do away with the custom state and extra workflow steps altogether if you simply refer to the datasource you’re already referring to in the Hazards RG (exactly as you are doing when you’re clicking the row in the Hazard RG - just use it as the default datasource instead).

There are always multiple ways to achieve the same outcome in Bubble, but generally the simplest way is the best.

Hi Adam - that works fine thank you!! The only issue now is I also want to select the first row in the Risk Controls RG as well. If I get this working then I think I have cracked it!!

Thankyou all for your help!!

Regards

D

You want to select that where? (but wherever it is, you should be able to simply refer to it’s first item)

Hi Adam

EDIT: got this bit working following a similar pattern so thankyou for all your help!!

So the behaviour I have now is I select a row in my issues log (which is on a different page). I load my Hazards RG and the Risk RG now displays the risk data that relates to the first row of the Hazard RG.

But I also want to then set the value of an input to a data item of the first record in the Risk RG. I have this working but only if I click the first row in the Risk RG and fire my workflow,

Thanks

1 Like

Hi, I came across this thread. I do not have 2 RGs, I just have 1 RG and am trying to get it up so on page load, it auto toggles the first item in the list (since I have the RG setup as an accordion). I was trying to follow the thread, but it does not really apply to what I am exactly needing: Envy Portal - Login