You do not have the correct permissions on the Data Collection. Save is not allowed by the User or Visitor (Anyone) on your Data Collection. Right click your Data Collection and set the permission accordingly.
The permissions are correct and some data does get saved. The issue seems to happen when $w(" #dataset1 ").save(); is called. Plus, onAfterSave doesn’t work in my lightbox, but works on dynamic and regular pages. However, onBeforeSave does work.
The problem is the .save() call inside your onBeforeSave() function, it is not necessary, the dataset will save after the onBeforeSave() function resolves.
Thanks! I’ll test it out. Why the save function then? Also, any idea why onAfterSave does not work in a lightbox? I’m trying to automatically close the light box. Right now, I’m using error detection in onBeforeSave() with a delay. If no errors are detected, I then delay the close, giving enough time for the data to save to the database.
After seeing and recreating your code, I believe the problem is the fact that you had set the field _id value as the user’s ID
$w('#dataset1').setFieldValue('_id', user.id);
The _id field is a unique system field which cannot be edited. even though you are succeeding in changing the values I believe that this is what causing the problems and if you comment-out that line, onAfterSave will work fine.
I suggest inserting the user’s id in a different field in your item schema.
UPDATE: After discussing your situation with another team we found that you can change the _id using the onBeforeSave hook and that is an issue on our side.
I will update this thread when there is new information regarding the issue, for the time being, what you can do is to remove the ‘Submit’ action from your button and instead giving it an onClick event with the following code
You can find everything you need in the API or searching the Help Center .
Regarding further educational videos, you can keep up to date in the Wix Tips and Updates Forum