Hi all. I’m new to Wix Velo here.
I am currently building a yacht travel website that requires a booking page. It is set up as a dynamic page from my “Trips” collection.
This page requires me to show the price of each cabin type, which I have included in my collection data as a “number”.
Now, since I need to format the prices in USD, I would like to connect one of my text elements, let’s say “#cabin1Price” to the “cabin1Price” field in my collection, and then format it as needed
I know how to do it on a dynamic page that shows all of the trips in my collection within a repeater, but how do I do it for a single item, in a container that is not a repeater?
Below is the code that I currently have for the other page (Schedule & Rates) that shows all of the trips, and I would like to implement pretty much the same thing (including formatting the dates), but only for one trip for the booking page.
import wixData from 'wix-data';
$w.onReady( async function () {
$w('#scheduleRatesRepeater').onItemReady(($item,itemData,index)=>{
$item('#itineraryName').text = itemData.itineraryName;
//Format starting price in USD, omitting the 2 decimal points.
let formattedPrice = itemData.cabinType1Price.toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0, minimumFractionDigits: 0, });
$item('#startingPrice').text = String(formattedPrice);
//Format "Departure" & "Arrival" in DD MMM YYYY, e.g. 2 Apr 2023.
const departureDate = itemData.departure;
let options = {
day: 'numeric',
month: 'short',
year: 'numeric',
};
let formattedDeparture = new Intl.DateTimeFormat('en-uk', options).format(departureDate);
$item('#departureDate').text = String(formattedDeparture);
//Combining "Disembarkation & "Embarkation" in one line.
$item('#embarkDisembark').text = String(itemData.portOfEmbarkation + " to " + itemData.portOfDisembarkation);
})
const {items:trips} = await wixData.query('ScheduleRates').find();
$w('#scheduleRatesRepeater').data = trips;
});
Thanks so much in advance!