Forum Academy Marketplace Showcase Pricing Features

[SOLVED] Checkbox to set value of "Price" field

Good Afternoon Bubblers,

I’m trying to figure out how to click a checkbox, and the clicked checkbox would set the “Price” field to $0.
This is all prior to actually submitting the form.

I’ve tried “make changes to thing” and element action “change state”, but no love.

I feel like a crazy person that I can’t figure out how to set a simple field from a checbox… Help?

https://bubble.io/site/chorus_marketplace/version-test/listing_new?debug_mode=true

Thanks!

Rob

You can hide the input when the checkbox is checked.

Then save the checkbox’s state on a field in your new thing:

1 Like

Thanks for the reply, George! If I create a new thing called “is_free”, like in your example, doesn’t that commit it to the database? If I wanted to set the Price field to “$0”, prior to saving, what would you recommend?

You could put the field in a group, then reset the group. If the initial content is zero, then it will zeroise the field. You probably want to disable input too.

Is this what you wanted ?

1 Like

Hi Nigel - thanks for your reply and help. Yes, this does what I want, and in a manner I hadn’t considered.
The behavior I’m looking for is more than just setting the value to zero, it’s setting pre-save values, but it sounds like there’s no real way to do a ‘Set Fields’ action (ex. Click this, update these fields prior to save)

I imagine it would be something in the workflow under “Element Actions” > “Input” > “Set Fields”, where you’d click a button/perform an action, and some field values would be populated (Again, pre-save).

quick thoughts:

  • using states as suggested by @georgeciobanu should work as u want. ‘is free’ state would be a boolean yes/no type not a db object. so no need to store it before actual save
  • you can commit object to db only when you’re done editing. at that point create the thing and associate its fields to the states on the form.
1 Like

I think you probably want “send data to group” on the action. That is how you can override values entered.

1 Like

Thanks Nigel - could you send a screencap of an example?

I was thinking I could create a “Free Price” Listing, that already had “$0” as the price, and send that data to the group (the “price” field, specifically), but it’s not working like I’d expect.

It is quite tricky to do this, as I think what you are thinking is to do a search for your “free” Listing.

The problem is that this will return a LIST of Listings. Not a single list. So you will get errors. What you need to do is do :firstitem so you only get one back.

Then you can send that to the group, and the items will pick up the group values that have been defaulted.

If you just have a single field it will be easier to set a custom state on page load and use that.

I have updated the forum up showing bringing back a single default thing and display it.

The initial values of the group fields are not set, so the placeholders are shown, but you could always set an “initial load” default and then override.

2 Likes

Yes. Yes. YES. This is exactly what I want to do! This works like a charm, thank you so much!
So, if anyone else is having trouble, from @NigelG 's example, I did this:

  • I had to create a new data type called “Default”

  • Then I created an entry in Defaults

  • After that, I made sure the ‘Price’ box I wanted to set to “0” was contained in a container of type “Default”

  • and I set the ‘Price’ field’s initial value to Prent group’s Default’s Default_Value (the field that holds the value I want to pass)

  • The final step was adding workflow to my “item is free” button:

  • Using the “Element Actions” > “Display Data” action, set up the Display data properties for the Group Text box (which contains my ‘Price’), Search for Defaults, where the Default_Name = “Default_Listing-Price” (my 0 value entry), and then pick the first item.

4 Likes