Does itemData update after submitting input to dataset?

I’m making a comments section where a comment can be edited by the current logged in member using a textbox linked to the dataset. This works fine and the comments repeater updates the comment in real time after the .save operation runs with this code:

   $item ( '#updateButton' ). onClick (() => { 
            $item ( '#commentReadWrite' ). setFieldValue ( 'edited' , 'Edited' );  
            $item ( '#commentReadWrite' ). save () 
            editOff (); 
            $item ( '#updateDate' ). show () 
            }) 

I have another window that opens on click for the specific comment, and the “subject” and “comment” are linked to the dataset manually:

$w ( "#commentReadWrite" ). onReady (() => {     
	$w ( "#commentsRepeater" ). onItemReady (( $item ,  itemData ) => {   
		$item ( "#itemReply" ). onClick ( ( event ) => {   
			$w ( '#repliesSubject' ). text  =  itemData . subject ; 
			$w ( '#repliesComment' ). text  =  itemData . comment 
			}) 
		}) 
	}) 

My issue is that the itemData does not get updated after the dataset is saved, so the repeater is able to update itself with the new information but the itemData operation doesn’t reflect the new information. I double-checked and this is the case when I do a console.log to see what the subject and comment are after saving - it’s still the old subject and comment.

Is this how it’s supposed to be, or am I doing something wrong? If this is how it is, how can I work around it?

To be able to see REFRESHED-RESULTS,… wait wait wait STOP !

WHAT ??? → REFRESHED ??? Ohhhhh, yes i remember…
https://www.wix.com/velo/reference/wix-dataset/dataset/refresh

Because i do not see any manual RELOADINGS of your REPEATER with new DATA, i assume you just have connected your repeater with the help of a DATASET.

And yes, i can see your DATASET … (commentReadWrite), you have used some connections inside of the PROPERTY-PANEL, to show data of your DB inside of your repeater. Didn’t you ?

Another hint…
https://www.wix.com/velo/reference/wix-dataset/dataset/onaftersave

Hi Velo-Ninja,

As I mentioned, the repeater is doing fine reloading with the new data just by using the .save() operation. So I didn’t see a reason to add the .refresh() there.

The problem occurs in the second part, with the popup window where I manually load the item’s “subject” and “comment” using code and have it show in text elements. Since the itemData isn’t updating, the text elements show the old information.

To illustrate this further, I added a refresh and then console log to the first part of the code:

$item ( '#updateButton' ). onClick (() => { 
            	$item ( '#commentReadWrite' ). setFieldValue ( 'edited' , 'Edited' );  
            	$item ( '#commentReadWrite' ). save (). then (() =>  			{ $w ( '#commentReadWrite' ). refresh (). then ( () => { 
	console . log ( itemData . comment ); })}) 
            	editOff (); 
            	$item ( '#updateDate' ). show ()    
           	 }) 

…and the console log is still showing the old comment.

I think I’ve encountered this before, where it seems like the itemData stays fixed even though repeaters are updating and when I go to the content manager, the collection is updated as well. It made me wonder if the itemData only gets updated when a new session starts. I’m still learning so please clarify if I’m missing something.

I would read this about using consistent Reads as this will likely help https://community.wix.com/velo/forum/news-announcements/wix-data-consistentread-read-your-own-writes

It is always better to see the whole code and not just some code-parts.

And what is that “window” you talking about?

I have another window that opens on click for the specific comment, and the “subject” and “comment” are linked to the dataset manually:

When you are describing your PROJECT-SETUP, please always do it in detail by using the right names for the related elements.

MULTISTATE_BOX
HTML-COMPONENT-
REPEATER
DATASET
COLLECTION/DATABASE
INPUT-ELEMENT
DROPDOWN
LIGHTBOX
…and so on…

So one more time the question —> what is that other window?

The popup window I’m referring to is just a container that expands when “Reply” is clicked for that comment. Here are 2 images for a repeater item (comment) that was just updated, and what happens when you click Reply:

I hope this helps - the code for this dataset was very long so I was trying to simplify, but I can post the whole thing if you need it! Thank you for your patience.

Thank you for the input - if I understand correctly, this is talking about a delay of a few seconds for the mirror instances? In my case, the itemData seems to NEVER get updated (unless I refresh the page), as I’m reopening the window and therefore re-firing the code for the text element minutes later and it still has the old information.

OK, I’ve linked the text elements to the dataset directly and changed the code to filter the commentsReadWrite dataset for that particular item when Reply is clicked. For whatever reason, this works and the updated comment shows. Please let me know if anyone understands why this is - it would be nice to learn about these details!