# Adding user-generated content

**URL:** <https://forum.wixstudio.com/t/adding-user-generated-content/41824>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 24, 2022, 5:48pm UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824 "2022-05-24T17:48:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stc1705](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stc1705/32/33511_2.png) [@stc1705](https://forum.wixstudio.com/u/stc1705)\
**Post date:** [May 24, 2022, 5:48pm UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824/1 "2022-05-24T17:48:13Z")

</div>

I tried adding user-generated content using the tutorial on the Wix YouTube channel, but the tutorial doesn’t show what I should connect my submit button to. What should I connect the button to?

The code I’ve used is:

**import** wixData **from** ‘wix-data’ ;

**function** getData ( ) {  
**let** query = wixData . query [‘Comments’];

```
**return** query . limit ( 1000 ). find (). then ( results => { 
    console . log ( 'getData' , results ); 
    **return** results . items ; 
}); 

```

}

$w . onReady ( () =\> {

```
$w ( '#dataset2' ). onAfterSave ( () => { 
    getData (). then (( items ) => { 
        $w ( '#dataset3' ). data = items ; 
    }); 
}); 

```

});

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [May 24, 2022, 7:52pm UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824/2 "2022-05-24T19:52:37Z")

</div>

Before you get some answers, you probably should first make a better description of your issue.

1. Which tutorial you were following?
2. Where is your current working (not working code) ???
3. How do look like your database ?
4. Do you use DATASETS, or Wix-Data (coding way) ???

Without all such important informations anybody will be able to help you!

Refill your post again.

---

<div class="post-metadata">

**Author:** ![stc1705](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stc1705/32/33511_2.png) [@stc1705](https://forum.wixstudio.com/u/stc1705)\
**Post date:** [May 25, 2022, 4:25am UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824/3 "2022-05-25T04:25:47Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [May 25, 2022, 10:44pm UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824/4 "2022-05-25T22:44:27Z")

</div>

@stc1705 Ok, after taking a look onto your code, i am able to say, that you must be relatively new to coding.

There are some issues in your code, also mixing DATASET-CODE with Wix-Data-code is not one of the best ideas. You better go either the one or the other way.

However, let’s switch to the issued code-lines…  
This is aproxiatively how your code should look like…

```javascript
import wixData from 'wix-data';
 
$w.onReady(async()=>{ 
    let foundResults = await getData('Comments'); console.log("RESULTS: ", foundResults);    
    $w('#dataset2').onAfterSave(() => {
        getData().then((items) => {
            $w('#dataset3').data = items;
        });
    });
}); 

function getData() {
    return wixData.query(DB)
    .limit(1000)
    .find()
    .then((res)=>{return res;})
    .catch((err)=>{console.log("ERROR occured!");});
}

```

1. On top you have all library imports
2. You always start your code with $w.onReady());
3. Functions should always be placed either to the right related code-line ot to the very end of your code. (but not neccessary.

And my most important tip for you… always take a look onto the VELO-API, to get info of all currently used elements.

Whats going on here…?

```javascript
$w('#dataset3').data = items; >--- maybe using a REPEATER here, would be better?)

```

Does .data somewhere exists inside dataset-api? Please check first.

But still something wrong with this code!!!

You said you need some actions when clicking the Submit-button ?  
The action is already given and the SUBMIT-BUTTON even do not have to be coded.

You click the SUBMIT-BUTTON → some saving prozesses starts, right?

And what happens next?

```javascript
$w('#dataset2').onAfterSave(() => {
      getData().then((items) => {
            $w('#repeater3').data = items;
      });
 });

```

Yes onAfterSave should run after saving-process.

Or i am today just overworked…to be continued! 😴

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [May 28, 2022, 9:30am UTC](https://forum.wixstudio.com/t/adding-user-generated-content/41824/5 "2022-05-28T09:30:53Z")

</div>

So what’s the last state here? Problem solved already ?
