Set state to current cells value

im sure i am missing something simple. can retrieve and iterate through the list (array?). but its breaking my brain trying to get the current cell value into a state, for later storage in the database. :firstitem gets me just that, :randomitem wont get me where i want to go. :item # might work if i can just figure out how to increment the counter. plz and ty

https://bubble.io/page?type=page&name=index&id=mlc-user-tut&tab=tabs-1

Thanks for posting an editor link, but you’ll need to change the permissions to “everyone can view” in order for anyone to take a look. Right now it just redirects to the homepage since it’s probably set to “private”.

Go to Settings -> General -> Application Rights = “Everyone can view”

Folks will be able to help you then.

:+1:t2: you were correct sir. thx for the heads up

Okay, you should be able to pull this off. I’m not sure which button you’re using to save the color as a state, but assuming it’s “save color”, here’s what I would do:

Step 1: Set the state
(This will save the color in RepeatingGroup’s custom state: zzzzzzzzzz)

  • When Button Save Color is clicked:
    Set State (in Element actions menu): RepeatingGroup’s zzzzzzzzzz = (color you want - probably just reference the text element inside the cell)

Step 2: Reference the custom state to populate “Text Get From State”.
(This should be fine as is)

  • Set value of “Text Get From State” to RepeatingGroup Colors’s zzzzzzzzzzz.

thanks for taking a look

is where im stuck.

if i select first item, thats all i ever get. the first item (red, in this example). if i dont select anything at this point, bubble gets mad and says im trying to show the whole list and not just a single record.

thanks again

Have you tried putting the save button inside the cell? That way you can access the “current cell’s” option.

yeah, thats the problem

the buttons are in a sidenav. i can get the “current cell” option when im inside the rg. but outside is a nogo. im thinking there are some global/local scope things im bumping into. i suppose i could extend the rg all the way over to the left but thats gonna get messy. you can see im pulling from many different lists so if i do that im gonna have stuff everywhere.

im trying to keep the db calls to a minimum but im thinking thats gonna be the only solution

Different approach:

Use 2 custom states:

  1. color (which is used to populate the text element)
  2. tempColor (used to hold temporary values as you cycle through colors)

As you cycle through colors, set the tempColor state to the current color.

When you click “save color”, use a workflow to set “color” to “tempColor”

That way, you won’t have to access a certain RG cell, you’ll have been passing it to the tempColor state ready to access later.

Hope that made sense.

yeah, i was just thinking along the same line, some sort of index thingy.

gawd, a “:nextitem” would be nice right about now. lol

2 Likes

Hi @jmadarieta

Either I don’t understand what you want, or it’s simpler, than you think :wink:

  • You are cycling through the RG’s items by pressing button(s)
  • RG’s current cell contains some data, either displayed or just taken from database but not displayed
  • You want that data or part of it to be used in another place, eg. in another element or state or whatever

If above is correct - then it’s really quite simple - check here: https://yamedia.bubbleapps.io/version-test/tests

How to:

  1. add custom state to your RG, call it current of type number; this will be your counter
  2. add On page load event and set this custom state to 1 (assuming your RG will have always minimum 1 thing on the list)
  3. add button next and the following set of actions:
  • Show next of repeating group …
  • Set state of repeating group current = repeating group current + 1; Only when RG’s current < RG’s items count
  • if you need Previous button - there is action for it as well; do as above, just in the 2nd step do RG’s current = RG’s current - 1; Only when RG’s current > 1

Voila!

Add any button or anything you want outside of your RG and now you can refer to RG’s List of items : Item # (#=RG’s current) followed by the field you want to grab (text, color, image - whatever your RG’s thing contains). In the example above I did skip that step and I take data directly to text and input elements, because you can’t see my states.

Hope that helps.

3 Likes

tenor

OMG :scream::scream::scream:

that did it! i knew there had to be a counter involved in there somewhere i just couldnt figure out how do that in a way made sense. thanks for the save!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.