Do I need to create another one? I thought one custom state can contain various bits of info?
For example, on my main app I have a custom state for invoice âline-itemsâ and that contains many different bits of data (price, quantity etc). I got help to create that set up so I am unsure how it was achieved.
Iâd like to know how we are âsupposedâ to do it, the best practice way to store info in a custom state and refer to it on another group? I have gone through so many tutorials and documentation but they mainly talk about using custom states to show or hide elements.
Basically, a custom state is a variable that can store things like text, number, date or an entire data type of your database.
A Data type is an iten from your database. So it will contain all fields of you data type stored in a single custom stateâŚ
Letâs say you have a table (data type) called Users. And in this table you have name, email, phone, and birthdate. If you save a specific User as a custom state, you will save all this usersâs data inside this custom state (name, email, phone and birthdate). But to do it, you need to tell Bubble that this specific custom state is an User instead a text or a number.
In your case you need to change your custom stateâs type from âtextâ to âFruitâ.
Thank you @rpetribu for the explanation. If I understand correctly, you are saying that I need to have a datatype in order to store the data in a custom state. If that is the case, I would need to add a data type âFruitâ and (as you say) change my custom stateâs type from âtextâ to âFruitâ.
But, doesnât this defeat the purpose of using a custom state to avoid the need of saving things to the database?
Maybe I should back up and explain my actual use case.
The reason for me wanting to learn this is because on my main site my users fill in some form fields to generate a PDF invoice. That invoice does NOT need to be stored in the database, but I do want to show it (one time) when they click Preview. Currently I save the PDF to the database, display it to the user when they click Preview and then later I will delete it from the database.
This seemed âclunkyâ so I was hoping I could save the PDF in a custom state and display it without it ever being saved to the database.
Store an entire User as a custom state can be useful for a lot of things like, as an example, have all the info about this user cached in your browser, what eliminates the necessity to make more queries in your database. This makes your app much faster.
But if you donât have the invoice already saved in your database, you donât have any invoice to be stored as a custom state, make sense? What you have is some texts and numbers that, together, will compose this specific invoice. In this case, your only option is to store the texts as text and the numbers as number and, in the end, you will be able to retrieve and display this info in some invoice template (without ever have needed to actually save this invoice in our database).
You are doing this in order to be able to show an invoice template (filled with some data) at the end of the process, am I right?
Thank you but I have already managed to create the invoice. I did actually follow that video last week, it was good but I found a lightly different solution. No, this thread really related to displaying the PDF (either in a popup or new group) without saving it to the DB.
Ok, this is where I may have gotten confused because I thought a custom state could store any information, regardless of if itâs in the DB or not.
Thatâs correct. The âsave invoiceâ button generates an invoice using PDF Conjurer. The final step in the Workflow is to save it to the DB. This works fine but, as I said, after a user has previewed their newly created invoice, I donât want it saved to the DB.
I thought I could save it to a custom state and show that to the user instead. In fact, the plugin owner suggested this solution to me in a separate thread.
And, if you want, you can also store a whole line of your database (called, âdata typeâ - User, Invoice, Car, Fruit⌠anything). But off course, to store all the information about a line, you need this line saved in your database .
To do what you desire, just keep saving the texts and numbers in different custom states and, in the end, retrieve this information to fill the invoice.
So, going back to the original task of asking a user to input a fruit name and colour and then storing that info in a custom state before finally displaying that info somewhere else, I would need two separate custom states, one to save the name and one for the colour. Is that correct?
I further understand from what youâve said that if I did save to the âFruitâ data type then I would have the advantage of only needing one custom state.
Thank you, I appreciate your patience! I have just set two custom states on my dummy webpage and the fruit info displays on the second page. I feel a bit more confident now that I am doing things correctly now so thank you again for your help.