I need help on my sites lightbox. I have connected a dataset to the lightbox but for some reason when I click my button to save the information to the database it shows that error in the title. Why is this happening??
Checks that I went through:
- Dataset is in “Write-Only” mode
- Code is exactly how it is from the reference page
- Did two error checks. The first error check (i.e., $w(“#recipesdata”).onError) showed up undefined for both of the consol.log’s below. Then the second error check that I put on the save function (i.e., . catch ((err)) , it said that there was an item that already existed in my dataset. Which I checked also and didn’t find any duplicates.
- Checked for duplicates in the dataset with the current items ID
Code (below):
let item = $w("#recipesdata").getCurrentItem()
let toSave = {
"name": $w("#recipename").value,
"teaser": $w("#recipeteaser").value,
"description": $w("#recipedescription").value,
"prepnumber": $w("#recipetime").value,
"preptime": $w("#recipetimedescription").value,
"servings": $w("#recipeservings").value
}
$w("#recipesdata").setFieldValues(toSave)
$w("#recipesdata").onAfterSave(() => {
console.log("id found - processing after save")
recipeId = item._id
console.log(recipeId)
changestep("two")
filterdirectionsonrecipeID()
filteringredientsonrecipeID()
$w("#reviewtime").text = $w("#recipetime").value + " " + $w("#recipetimedescription").value;
})
$w("#recipesdata").onError((operation, error) => {
let errorOp = operation; // "save"
let errorCode = error.code; // "DS_VALIDATION_ERROR"
let errorMessage = error.message;
// DatasetError: Some of the elements validation failed
console.log("id found - error")
console.log(errorOp)
console.log(errorCode)
console.log(errorMessage)
})
$w("#recipesdata").save()
.then((items) => {
let fieldId = items._id;
console.log(fieldId)
})
.catch((err) => {
let errMsg = err;
console.log(err)
});
Please help me find out why this is happening to my site. I am really trying to save the information.