Hi all, after some much needed help!!!
I have had some coding from Code Queen and had further advice to replicate some lines of code and change dataset names to have the same action with a different outcome. As you can see from the attached picture, the code has no highlighted errors and has half functionality.
Everything down to line 17 works fine. After that I have replicated the code and changed dataset names to have a different outcome.
In dataset 4 I have the same field as dataset 2 2, this is called - emailreference. This creates a individual input to a repeater that only appears on a users designated page.
All the code above line 17 makes this work for dataset 2. but the code below doesnt allow this. Can anyone see why??
Why do you need to have to get dataset1 onReady twice?
Plus, can you not just group all the dataset onReady functions together in the pages onReady function…
$w.onReady( () => {
$w("#myDataset").onReady( () => {
Then just have the lets and then the two onBeforeSaves with the setFieldValues in them.
You won’t need a save here as onBeforeSave does something before calling a save itself.
The other option here is to replace the onBeforeSave with a normal save after your setFieldValue calls.
$w.onReady( () => {
$w("#myDataset").onReady( () => {
$w("#myDataset").setFieldValue("title", "New Title");
$w("#myDataset").save();
});
});
Also, if you are just getting the one field item from the dataset you can just call that field in the getCurrrentItem call.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem
getCurrentItem as it is gets everything from the dataset for this.
Get the dataset’s current item when the page loads
$w.onReady( () => {
$w("#myDataset").onReady( () => {
let itemObj = $w("#myDataset").getCurrentItem();
} );
} );
/* itemObj:
*
* {
* "_id": "fcec780a-3e37-4b64-8a66-37c552c53f99",
* "_owner": "f6c0f9c3-a62d-7e9f-g58d-943829af244d9",
* "_createdDate": "2017-05-01T17:19:03.823Z",
* "_updatedDate": "2017-05-01T17:19:10.477Z",
* "title": "Dr. ",
* "name": "B",
* "link-dynamic-name": "/myCollection/B"
* }
*/
If you just want the one field, then just use the field key of that specific field after the getCurrentItem call, like this.
$w("#dataset1").getCurrentItem().fieldkey;
This will then just get the current item from only that field and return only that instead of everything as above.