I was able to calculate the total price in the shopping cart area, it calculates properly except the comma i added as separator does not seem to work. I also wanted to put a peso currency on the Price but I can’t figure it out. The one you’re seeing is just a text fixed there written as ₱. can you please check my code?
I highly appreciate a lot if you somebody is kind enough to help.
I’m having trouble getting this to work. Would you mind showing me some example code of how this is supposed to work to get 40000 to look like $40,000?
Something like this if value came from input1 & input1 input type is set to number. Otherwise you’d need to parseFloat the value to convert it to a number.
let price = "$" + $w("#input1").value.toLocalString()
Thanks, Tiaan. That worked!! Now, to have it show up inside a repeater… The value is coming from a database as a number. Would this still work or would I have to create some sort of foreach thing?
@tiaan … I’m trying to use the foreach function, but I don’t think I’m doing it correctly. Would you mind looking at my code and sending something that would work?
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
populateCalculatedFields();
} );
@tiaan , I was able to get the following code working… but it’s only on the first page of the repeater. Any idea how to get the prices formatted for the other pagination?
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
populateCalculatedFields();
} );
I haven’t had the need to try, but if I had to take a wild guess I’d probably call these functions again whenever the pagination has been clicked. I suspect it might need to re-render the new data.
Hello guys, I’m new to coding. Especially Velo, but I’ve tried my best to understand it. I’ve tried all the tutorials here at the forum but I always get an error like “Property ‘value’ does not exist on text type.” In my Content Manager, I already changed the property type from text into number but still got an error. What have I done wrong? Please help.
For anyone still having trouble using .toLocaleString() to display commas to a Number Field from a dataset in a repeater, here’s the code that I used which works perfectly for me:
$w . onReady ( function () {
$w ( “#yourDataset” ). onReady (() => {
$w ( “#yourRepeater” ). forEachItem (( $item , itemData , index ) => { let number = Number ( $item ( “#repeaterTextBox” ). text ). toLocaleString ();
$item ( “#repeaterTextBoxID” ). text = number ;
})
})
});
Plug in the ID’s for your page’s elements and this should display the number values in “#repeaterTextBox” with commas in them in preview/Live after the page loads.
If you also have dynamic pages for each of your dataset/repeater items, you can add this code in those pages as well:
$w . onReady ( function () {
$w ( “#yourDataset” ). onReady (() => { let number = Number ( $w ( “#textBox” ). text ). toLocaleString ();
$w ( “#textBox” ). text = number ;
})
});
Note: Remember that the element ID’s may be be different in this page so make sure you change them accordingly if that’s the case