Did you got that code from Chat-GPT? Looks like Chat-GPT programmed for you.
When working with connected DATASETS inside the PROPERTY-PANEL (and that’s exactly what you did, your CODE is wrong and won’t work like you expect it.
Forthermore if you have an UPLOAD-BUTTON → which needs time for UPLOADING DATA, you will need an asynchronous function to wait first until results and then proceed your process.
Whenever you work with connected DATASET inside property-panel → always think about 2-things…
Depending on how exactly to seted-up your page…(SUBMIT-BUTTON also connected inside PROPERTY-PANEL with the DATASET ???)
- Waiting for DATASET to be ready first → (this point was done by you already)
- Using the onBeforeSave() + onAfterSave()-hooks!
The second mentioned tip, explains why you get doubled saved data inside of your DATABASE.
Try to rewrite your whole code.
- First make clear which connections are settep-up inside PROPERTY-PANEL.
a) SUBMISSION-BUTTON connected to dataset inside PROPERTY-PANEL ?
To which dataset is connected your SBMISSION-BUTTON?
Is your SUBMISSION-BUTTON connected to a DATASET at all?
b) REPEATER connected inside PROPERTY-PANEL with DATASET?
c) How much datasets i am using?
d) Which kind of datasets i am using (dynamic / non-dynamic) ?
BASIC CODE when working with connected DATASET…
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
});
$w("#dataset1").onBeforeSave(() => {
});
$w("#dataset1").onAfterSave(() => {
});
});
You are using 2-different kind of DATASETS → a dynamic one and an ordinary one …
- $w(“#dynamicDataset”) —> DYNAMIC DATASET on a DYNAMIC-PAGE
- $w(“#dataset1”) --------------> ordinary dataset placed aswell on a DYNAMIC-PAGE.
When you describe your project-setup, make clear all details in your description.
For example…
I have a dataset (dataset1) on a page.
You do not tell that you are working on a DYNAMIC-PAGE!!!
So, wait!!! We have 2 DATASETS working on your page right?
But i see just one DATASET is getting ready…
$w("#dynamicDataset").onReady(() => { });
What about ----> DATASET1 ???
You are talking about —> dataset1 <—, but scanning your code, i can’t find any code-line where you are working with dataset1 !!!
Before you continue with coding, first make some thoughts about your complete setup, this is important.
And the last tip —> when you are not an experienced velo-programmer → try not to mix Wix-Data-Code with a setted-up dataset —> in most cases you will get issues.
Either go the one way, or go the other one (DATASET vs. Wix-Data).
To many open questions in your setup.
Once in the past i also worked with UPLOAD-BUTTON, so maybe the following code can be an example for you…
That was my upload-routine… (old one, but should still working)…
$w("#myUploadButton").onChange(()=>{
console.log($w("#myUploadButton").value);
//code...
//code...
//code...
UPLOAD();
});
function UPLOAD() {
if ($w("#myUploadButton").value.length>0) {
$w("#myUploadButton").uploadFiles()
.then((uploadedFiles)=> {
let fileURL = uploadedFiles[0].fileUrl
console.log("Uploaded-File: ", uploadedFiles[0]);
console.log("File-URL:" + uploadedFiles[0].fileUrl);
const parts = fileURL.split('/');
const extractedFilePath = parts[3];
console.log("Extracted-File-Path: ", extractedFilePath);
endURL = "https://static.wixstatic.com/media/"+extractedFilePath;
let counter = 0;
function checkStatus() {
if(endURL===undefined){return false;}
else {return true;}
}
function startFunction() {counter++;
console.log('Starting function..'+counter+'.');
}
let intervalId = setInterval(function() {
if (!checkStatus()) {startFunction();}
else {clearInterval(intervalId);
$w("#dataset1").save().then(()=>{console.log("Data has been saved!!!");});
}
}, 1000);
})
.catch((uploadError) => {
console.log("File upload error: " + uploadError.errorCode);
console.log(uploadError.errorDescription);
});
}
else {console.log("Please choose a file for upload.");}
}
$w("#dataset1").onBeforeSave(async() => {console.log("Before-Save running...");
let itemData = {
title:$w('#inpPositionTitle').value;
xxxxx:$w('#xxxxxxx').value;
zzzzz:$w('#zzzzzzz').value;
yyyyy: "what-ever-data-here";
}
$w('#dataset1').setFieldValues(itemData);
return true;
});