setFieldValue is not a function error

Hi

I am new to Wix and am encountering a weird error that is prevention a collection data entry.

I have a change event attached to an address input. The intention with this is to store the address I have as both a string and an address (I display the string value for each collection item as part of a repeater elsewhere in my site).

With the below code I keep getting a very weird “setFieldValue is not a function” on the second last line of code here and as a result the input to the collection is not working:

export function addressInput2_change ( event ) {

**let**  textAddress  =  String ( $w ( "#addressInput2" ). value ); 

$w ( "#dataset3" ). setFieldValue ( 'addressString' ,  textAddress ); 
$w  ( "#dataset3" ). save ();  

}

I can’t seem to see any other posts that deal with this but would love to know what I am doing wrong? Is there an actual error/is this not best practice/any other suggestions?

Thank you!

@nickvonroretz You would get that error on the setFieldValue function if you don’t have the name of the dataset precisely named. For instance, if the real name of the dataset is “#Dataset3”, with the first letter capitalized, it would give you that error. In that case, you should see a red squiggly line underneath the “#dataset3” in the editor. The Velo editor does a check to see if any of the elements that you are referencing are actually on the page.

That’s just one possible explanation for the error. There could be others.

Weirdly, what solved this was exiting the page, closing the browser/restart and re-entering… Not sure if it could be as a result of caching but it wourked with the same code as above later on

Not sure, but normaly when working with DATASET, you also need the onReady-action.

$w.onReady(() => {
  $w("#dataset3").onReady(()=> {
    $w("#dataset3").setFieldValue('addressString',textAddress);
    $w ("#dataset3").save();
  });  
});