Please help - this is driving me nuts.
I have a repeater in a dynamic page. I am trying to change the date format of an element in this repeater, pulling the original data from a database. I DO have the database connected to the overall repeater, but DO NOT have a field directly connected to the text element that I want to display the date. It works fine when I try it in preview. But when it's live, when a page loads, it will flash with the correct formatted date, then change to the template text of the repeater. The developer console is not flagging anything.
Here is the code:
$w.onReady(function () { // FIELD TWO $w("#repeater1").onItemReady(($w, itemData, index) => { const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; console.log(itemData.startDate); console.log(itemData.startDate.getDate().toString()); console.log(monthNames[itemData.startDate.getMonth()]); console.log(itemData.startDate.getFullYear().toString()); console.log(itemData.startDate.getHours().toString()); console.log(itemData.startDate.getMinutes().toString()); const strDate = itemData.startDate.getDate().toString(); const strMonth = monthNames[itemData.startDate.getMonth()]; const strYear = itemData.startDate.getFullYear().toString(); const strHour = ("0" + itemData.startDate.getHours().toString()).slice(-2); const strMinute = ("0" + itemData.startDate.getMinutes().toString()).slice(-2); $w("#text1").text = "Start: " + strMonth + " " + strDate + ", " + strYear + " " + strHour + ":" + strMinute; }); });
I am not a developer and would appreciate anyone's insights into what's going on there. Many thanks!!!
Sounds like the problem I was having here https://www.wix.com/code/home/forum/community-discussion/wix-code-changes-revert-after-a-few-seconds-on-page-load
It's a bug, which will be fixed, but as a temporary workaround I may suggest you to initialize new date object from a value (note the use of 'new')
let myDate = new Date(itemData.start);
Thank you!
Yes, the collection is synced.
I am trying to change a date to 12 hour time (ideally with AM/PM).
URL: https://www.indivisible-ma.org/Vol-Activities/AZ08
This is a dynamic page. There are multiple places, apart from this dynamic page, where I would like to change these dates on the website.
With the above code, this is what happens when the published page is loaded:
https://www.screencast.com/t/nLYpXphaIlR
(also, the hour should be showing as 00:00. I don't know why it's showing as 04:00)
Here it is in preview mode (it's correct here)
https://www.screencast.com/t/7gxQWd0leY
And here is what the back end looks like:
https://www.screencast.com/t/z1FSqvR2C
https://www.screencast.com/t/0DqM9KN2
https://www.screencast.com/t/RMoidFJ6p
Here is what it looks like without the code if I directly connect the dataset field to the text box:
https://www.screencast.com/t/WXOFpOmXRg
Let me know if there is anything more you need.
Many thanks!
Hi,
Have you synced your collection to the live site?
Should the issue persists, please send us the site URL and a video of the issue using screencast so that we can better understand what you were referring. Simply recreate the issue while recording the steps. Add the screencast.com URL to your response.
Thanks,
Tal.