Submit button not working

Hi

I have a dataset (dataset1) on a page. This dataset populates a repeater with photos from a collection. The photos displayed are determined by a dropdown (dropdown1). I have checked the collection permissions and they are set to public so anyone can read, edit, add, or delete.

I dataset1 is set to read & write. The acquisition of the data and display all works great.

Within the repeater I have added an upload button which I think works as when I click on the button in preview it allows me to select a file and then shows the filename after.

When I hit submit however nothing happens. I have added success/failure messages and nothing happens there either. t will work if I change the dataset to write only but then I don’t get any data in the repeater on the load of the page. I tried adding 2 datasets pointing to the same collection however that then seems to add duplicate records.

Do you use some code?
Where is your code?
You are in the CODE-SECTION of this forum.

import wixData from ‘wix-data’ ;

$w . onReady ( function () {
$w ( “#dynamicDataset” ). onReady (() => {
const currentItem = $w ( “#dynamicDataset” ). getCurrentItem ();
const recordId = currentItem . _id ;
console . log ( "Current record ID: " , recordId );
console . log ( "Current items: " , currentItem );
});

$w ( “#listRepeater” ). onItemReady (( $w , currentItemData , index ) => {
const recordId = currentItemData . _id ;
console . log ( "Current record ID: " , recordId );
console . log ( "Current items: " , currentItemData );

$w ( #button ${ index }). onClick (() => {
const inputValue = $w ( #input ${ index }). value ;
console . log ( "Input value: " , inputValue );

const ratingValue = inputValue ;

if ( currentItemData . gradeTest === undefined || currentItemData . gradeTest === “” ) {
wixData . insert ( “contact03” , { “gradeTest” : ratingValue })
. then (( results ) => {
const item = results ;
const newRecordId = item . _id ;
console . log ( "New record ID: " , newRecordId );
console . log ( "New gradeTest value: " , ratingValue );

    **const**  updatedItem  =  $w ( "#listRepeater" ). data [ index ]; 
    console . log ( "Updated items: " ,  updatedItem ); 

    $w ( `#text ${ index }`). text  =  "Grade marked" ; 
  }) 
  . **catch** (( error ) => { 
    console . log ( "Error while saving rating value: " ,  error ); 
  }); 

} else {
wixData . update ( “contact03” , { “_id” : recordId , “gradeTest” : ratingValue })
. then (() => {
console . log ( “Rating value saved successfully.” );
console . log ( "New gradeTest value: " , ratingValue );

    **const**  updatedItem  =  $w ( "#listRepeater" ). data [ index ]; 
    console . log ( "Updated items: " ,  updatedItem ); 
  }) 
  . **catch** (( error ) => { 
    console . log ( "Error while saving rating value: " ,  error ); 
  }); 

}
});

if ( currentItemData . gradeTest === undefined || currentItemData . gradeTest === “” ) {
$w ( #text ${ index }). text = “Grade not marked” ;
console . log ( “Grade not marked” );
} else {
$w ( #text ${ index }). text = “Grade marked” ;
console . log ( “Grade marked” );
}
});
});

can you look at this code kindly what i am doing wrong?

Did you got that code from Chat-GPT? :grin: 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 ???)

  1. Waiting for DATASET to be ready first → (this point was done by you already)
  2. 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.

  1. 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 …

  1. $w(“#dynamicDataset”) —> DYNAMIC DATASET on a DYNAMIC-PAGE
  2. $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;
});

Cone-Ninja

yes initially i have written a code that is not working so i used chatgpt and still no luck so i have removed the dropdown and now scenario is that there is repeater called #listRepeater which populates data from dataset called ‘contact03’ contain field called gradeTest which is numeric field in dataset. and i have a input box called #input1 and a button called #button1. So i want to collect input from #input1 and when onclick #button1 then insert value of #input1 in gradeTest in dataset contact03 so can you help me in this

Next time please reply to the right answer-section.

As i assumed it was a GPT-generated answer (typical failed answer).
Chat GPT can’t see what/and how you have connected (setted-up) all your page-elements. It depends on your setup!
There are avarious of options how to setup your page and all the connections.
If you would not use all the datasets, maybe chat-gpt would be able to help you a bit more, because in this case you would work more with code instead of using predefined (fixed) stuff (including datasets).

To be able to help you, i would first need to see your setup directly.
If i am honest, i don’t want to recreate again and again all the fail-projects (when using datasets) just to be able to help you.

It is very time-intensive work.
1) First do all the recreation/reconstruction of your setup
2) Inspect/analyse and find your issued error
3) and generate again a whole post to give you the right answer.

I gave you some hints which should help you out.
First take your time and read all the tips, given in this post.

Make clear thoughts about your project-setup.

You can make a STEP-LIST…

Step-1: Clicking the Submission-Button (button is inside repeater)
Step-2: xyz-function() starts or what ever
Step-3: …and so on
Step-4: …and so on

Then take a look onto this Step-List and check if you have systematic errors, or a flow-error.

Are all your steps in the right oder?
Do all of your if-else-conditions work?
And so on…

Paste console-logs → to see whats happening inside your code (but this point you already do, like it seems).

If you then still not able to DEBUG your own code → you will find my e-mail in my PROFILE. Let me know.