Happy Friday Bubblers!
I am trying to set an element’s data source based on which items are selected in a repeating group of checkbox items.
I have 2 tables with the schema below:
Card: Question (text), PartNum, (text)
TOBpart: PartName (text), PartNum (text) …trying to use PartNum in an SQL ‘foreign key constraint’ type of thing.
‘TOBpart’ is the source of the checklist group.
I had hopes that setting a custom state of Selected = ‘Yes’ on TOBpart’s checklist item and then using “intersect on” function when TOBpart custom state = yes would be the ticket, but alas, no dice. (or I just can’t get the logic syntax right)
Ultimately I’d like to have a text box display the result of something like:
Search for Card’s:random item (with a condition/filter of TOBpart selected = ‘Yes’)
Can anyone assist with where my Bubble noob is showing? Much please and thank you!
Happy to post screen captures if needed, just didn’t want to inundate the post with images.
I took a look at your editor, but I’m unsure what you’re trying to do. What do you want to want to happen when the user has selected entries in the TOBpart RG?
If you look at the ‘flashcards’ page, there is an element called CardQ group. It is the parent of a text field called ‘Question’. The data source for the Qcard group is ‘Search for Cards:random item’. The data source for the Question text field is ‘Parent group’s Card’s Answer’. I would like the questions displayed by the ‘Question’ field to be filtered based on which TOBparts are selected (checked). Make sense?
I’m more than happy to do the research to figure this out. Just need someone to point me in the right direction. I was up until 4am last night trying to figure this out with no luck. Lots of rtfm, try something, rtfm some more, try something else, rinse and repeat.
I don’t know of an efficient way to do it using the checkboxes in the RG, but this should work using a custom state:
- Create a custom state called something like “TOBSelections” of type TOBparts. Make it a list.
- Then create 2 workflows for when the checkbox is clicked.
2.1 Conditional: if the custom state TOBselections does not include the TOBPart, plus it to the custom state.
2.2. Conditional: if the custom state TOBselections does include the TOBPart, minus it from the custom state.
- Then in your search in the group, add a constraint to your search for cards: TOBPart is in the custom state.
I was thinking of a similar approach (making a sort of temp table to store the selected items) but I couldn’t figure out how to create a list. I think I get what you’re saying about making a custom state that is a list. I like it! My only question is, to which element would the custom state belong? TOBparts? And if so would it be the parent RG or the checkbox holding the state?
You can make the custom state part of any element. I just add all of mine to the page itself. Makes it easier to manage as your custom states grow.
Ahhh, I didn’t know that. You learn something new every day! I’ll give it a go. Thanks for the suggestions!.
Well, I hit a snag…
I created the fist Workflow shown below…
But in the action config I don’t see a way to (:plus) modify a state. I can modify the state of an element, but not the state itself.
All custom states are associated with some element. Just select the element you chose to put the state on. You’ll then see the available states in the Custom State dropdown (which also lets you create a new one if you wanna).
It’s the one right under the element dropdown in your screen capture.
As @keith stated, the state is under the element. Then you plus to the existing state of the custom state.
Here is a similar example from my world:
Of course, if your state is on an element in an RG, you may not be able to target it.
I added the custom state to the Checkbox Current cells TOBpart.
Got everything in place with the Workflows and actions as you guys directed…I think.
But it doesn’t seem like I can associate the custom state in data source query or a condition.
Side note… I really appreciate all the help!
I think I may not have emphasized a critical piece. The TOBparts are categories of items (cards) in a DB table. They do not represent the card’s question text values to be searched/displayed in the “question” text field. The check boxes should cause all cards in the selected categories to be put into the list, temp table (ultimately the list of things in the array). There is also a table called TOBparts. The Cards table and the TOBparts table both have a PartNum field which I was hoping to use in a fashion similar to a SQL foreign key constraint that could be used as a ‘join’ clause.
Edit: If the above assumption is correct and there was a misunderstanding in the ask, should I delete all of the posts with recommendations and images not pertinent to the actual question?
I was able to get this working by using a custom state. Thanks for that suggestion @SerPounce. The working solution was a little more complex due to the the logic of categories based on the check boxes but I wouldn’t have gotten there without your explanation of custom states.
Step by Step Solution below for anyone facing this issue in the future:
Step 1: Create a custom state on your page or parent group. Check “List”
Step2: Create a “When changed” event for the element “Checkbox current value” and set Only when the custom state “doesn’t contain” the corresponding checkbox’s unique identifier (PartNum in my case).
Step 3: Within the event create an action (step) that will add the category’s corresponding identifier (PartNum) to the state.
Steps 4 and 5:
Repeat steps 2 and 3 but reverse the logic for the event and action. The event should state “contains” vs “doesn’t contain” and the action (step) should minus the category identifier (PartNum).
Step 6: Set a constraint on your data source to only return results for items that have a corresponding identifier to those in the custom state list.
You must have a way to link the two tables of categories and and things (the field of PartNum in both TOBparts and Cards in my case) that exists in both tables to provide a function similar to a foreign key constraint in SQL.
Hope this is helpful to someone else!
Thanks! it looks like this is what i need… but i’'m hitting an issue here with adding a list-item to my state in the workflow for either :plus, or :minus … it goes red when trying to input my number field [inspID] (see screenshot)
(i have this issue elsewhere on bubble as well, i have to add ‘decimal’ formatting to the end of this string for bubble to let me save, but it still won’t enter into my app data for some reason)
What is the error that is displayed in the issue (issues listed in top right corner)