Formatting Xano/Rest currency fields

Newbie here. I have figured out how to connect my Xano data base to a weweb collection. In it I have a field called cost, which is stored as a decimal. I have successfully linked it to a text field but I cannot for the life of me figure out how to now format it as $currency. How do you do this?

Welcome.

What currency do you want to format it as?

I live in USA. So, I created a custom function to convert an integer.

Here is how you can do it:

  1. Click on the data tab in the tool bar Screen Shot 2022-04-23 at 11.19.48 PM

  2. Click on +Add Formula

  3. name the formula. I used toCurrency

  4. add 1 parameter, name it whatever you want (I used ā€œitemā€), and select number from the drop down.

  5. in the function box, you will want to use something like below. The below code is JS that will take the incoming parameter, and apply the toLocaleString() Js function to it and return that.

return "$" + item.toLocaleString("en-US", {
    style: 'currency',
    currency: 'USD'
});

There are all types of different options in the toLocaleString, so google that and youā€™ll find your country.

Once you have that done, now you can use the function anywhere in your site.

Go to the text that you currently have bound to your database. Click on the functions area (see image below), scroll down, and click on Custom.

This will show your custom function.

Use that, and put your decimal database value into there. It will return your currency.

3 Likes

OKā€¦I think I get it, though I thought the whole point of this was nocodeā€¦
But when I try it I get an error.
Hereā€™s my formula entry which seemed to go well:

Appreciate your help!

And here is my attempt at using it, which is returning an ā€œunexpected identifierā€

Hmm. That looks good. Can you take out the item[ā€˜dataā€™][ā€˜cpuā€™] and just put in a number.

try toCurrency(25)

Does that work?

Also, you wonā€™t need the ā€œ$ā€ +, since that will come through the toLocaleString function.

OK, gave that a try. Changed it to:
toCurrency(25) and I still get ā€œUnexpected identifierā€

Also, I donā€™t know what that means. Iā€™m guessing you are suggesting dropping the ā€œ$ā€ + from the formula definition. which I will try.

Ah! I see it! You need a comma after currency:ā€˜USDā€™

It should be currency: ā€˜USDā€™,

Kevin, THANK YOU! that fixed it.

Nicely done! Well done to both of you :grinning: :raised_hands:

You could probably put something similar with the existing math and slice no-code formulas but @kevinwasieā€™s solution is more elegant.

Iā€™ve added ā€œno-code currency styling formulasā€ to our list of product improvement requests so itā€™s more straightforward in the future :slight_smile:

Thanks Joyce!
Iā€™ve been watching all of your videos. They are incredibly helpful. Thank you so much. Iā€™m a bubbler and the transition was a bit rough at first, but I think Iā€™m starting to get the hang of it as I slowly rebuild a former bubble app on weweb/Xano. Front end design is so much easier as is some of the logic of state/variable management. Though database integration is still a learning curve for me.

One ask for a video or tutorialā€¦
A commonly used feature in bubble for me is the checkbox called ā€œEnable auto-binding on parent elementā€™s thingā€. When checked for an element (say a text box in a repeating group), the controls allow the user to edit the field and on update, reflect the change results back into the data of the ā€œThingā€. I use this when I donā€™t want the properly permissioned user to have to open a separate form or pop-up simply to edit and submit a record. To mimic this functionality in WeWeb I assume I need to use a form control (say short text), populate itā€™s initial value with the current database value, then create a workflow action for the field that if updated, on change, posts the revision back to Xano using a POST Api. Yet for the life of me I havenā€™t been able to figure out how to do it, so Iā€™m guessing I might be setting up the POST wrong.

Is there a tutorial that might help me understand how to replicate this, ā€˜auto-bindingā€™ functionality?
Al

Hi @Aloy :wave:

Thank you for the kind words, really appreciate it! :slight_smile:

Hereā€™s a tutorial on how to pre-fill a form with the current database value. The tutorial is with Airtable but the logic is the same for Xano except, as you mention, youā€™ll have to create your own POST request.

Can you maybe create a new topic in the community and share a loom showing how things are currently setup in Xano and WeWeb, what youā€™re trying to do, and what error message you get from Xano when you test the action?

(a separate topic would be great because it helps others search for answers)

Can you please share an example of how to do it the no code way, also if there is a way to format for %