Forum Academy Marketplace Showcase Pricing Features

How do you populate dynamic dropdowns based on a number field?

I’m trying to wrap my head around a simple stock management feature.

Users are saving a stock value [number] to the DB, which is presented on the front-end to customers. Is there a way to populate a dynamic dropdown list based on that stock value? E.g. stock = 10, dropdown should render 1-10, stock = 20, dropdown 1-20.

Any other suggested ideas of how to set it up?

When you say stock, are talking about inventory? So if you have 20 widgets you want the dropdown to display a quantity of 1 to 20?

I think the dynamic dropdown values are pulled from lists of things, so you’d have to set up a list with 1, 2, 3, etc. up to the total and set that as the data source for your dropdown.

When you say stock, are talking about inventory? So if you have 20 widgets you want the dropdown to display a quantity of 1 to 20?

Correct. I’m trying to figure out the best way to create and manage the inventory backend and frontend.

Users define a stock. That needs to be handled on the frontend and updated on the backend, saved to DB decrementally approaching 0 as customers buy items.

I’m thinking dropdown with stock displayed as you suggest.

I guess you could also go with +/- fields with values matched against the actual stock value, but that would need to have a <0 breaker to avoid negative values. Or input field with the same need for negative value prevention.

I think the dynamic dropdown values are pulled from lists of things, so you’d have to set up a list with 1, 2, 3, etc. up to the total and set that as the data source for your dropdown.

Right. How do you see this working when using a dropdown with dynamic data and that list needs to change for every product? E.g. product 1, stock = 9, product 2, stock = 7 etc. > product 1 list 1-9, product 2 list 1-7

You’s either have to add a separate quantity list for each product or perhaps set constraints based on the product. I’d have to play around with it to figure out if that’s possible. However, I’m not sure that a drop down is the best way to go.

What if there are hundreds of a particular item in stock? That dropdown would be really long, which doesn’t make for a great User Experience.

I agree that dropdown is probably not the best when you the number available could be very high and cumbersome to scroll through. I’d have a stock field (type number) in the product data type. On the front-end, use a text element to display this value so that users can see how many are still available. Next to it, have an input available for the user to type in the quantity they want. In the workflow for “buying” (or whatever it is users are doing), you Make a Change to Thing (your product) > Stock (field) = This Product’s Stock - Input Value

To prevent negative numbers, add a condition on the input element to disable it: When This Product’s stock is 0, this input is disabled.

Let me know if this helps!

Edit: Also! You’d need to set a max value on your input (type integer) to prevent users from entering values greater than stock available: it would just be “This Product’s Stock”


Gaby | Coaching Bubble

You’s either have to add a separate quantity list for each product or perhaps set constraints based on the product. I’d have to play around with it to figure out if that’s possible. However, I’m not sure that a drop down is the best way to go.

Yeah, that’s how I also see it. That’s not going to be possible. The lists wouldn’t be dynamic. The stock value is user defined. It would be easy using arrays and some more logics. stock value = 10, dropdown =1-10.

What if there are hundreds of a particular item in stock? That dropdown would be really long, which doesn’t make for a great User Experience.

In this example, there’s not going to be hundreds in stock, more like 1-20 max. You couldn’t know that obviously :slight_smile: You’re right about the UX. Same would go for @romanmg’s suggestion about the user to type in wanted quantity. At least not optimal but good enough.

Thanks for your input @romanmg! Your solution is very most likely the one to go with. Reason why I like the dropdown is because it would be easily implemented IF it’d be possible to populate a dynamic dropdown based on a number field.

I’d like to keep it simple but let’s see :smile:
Keep everyone updated about solution.

A simple solution is to have a data type with a list of numbers from 1 to x. Then in your dynamic search have a condition that says where number < the number in stock. Then sort so you get 1 > x.

hmm, there’s my array function workaround. That list could be used in many instances as long as I make sure to make it > than any potential stock value a user might define (or put a max on the value).

Hi Nigel,

quick question about this old post: how can I create a list of numbers from 1 to x ? In my app users can book sailboat vacation and I need a dropdown showing how many seats are left on the boat. Number of total available seats is usually from 2 to 8 so I would like to create, for each sailing vacation, a list with 1, 2, 3, 4, 5, 6, etc. up to the total number of places available. Then when someone books one or more seats, I remove them from the list.

I do not know if this is the smartest way to manage this situation, but I got lost in creating a simple list of numbers.

Wonder if you can help me (I have been reading so many of your useful solutions)

Many thanks

Hi,

I would still think that creating a very small data type with the numbers 1- x on it is the way to go.

Then in your search on the Dropdown you would add something to limit the numbers returned <= spaces available.

1 Like

Thank you so much ! I have wasted a lot of time looking for more complicated solutions when it was so simple :slight_smile: