Hi Eitan,
I am trying to follow this video of yours to achieve something similar, however the code would just not run on hitting that SUBMIT button.
I have checked the complete code and I couldn't find any error of any sort. What am I missing here?
The Web URL: https://www.bizzness.co/form/aditya-birla-fashion-and-retail
Note 01:
a) The code below is edited only for the 1st 7 fields, starting with 'Full Name', 'Designation' up till 'Website'.
Note 02 :
The Code:
//--------------------------------------
// Code to UPDATE dataset entries
import wixData from 'wix-data';
$w.onReady(function () {
const myCollection = "MS";
let idToUpdate = "";
// Calling & Displaying all data fields
const selectItemForUpdate = (itemData) => {
$w("#input15").value = itemData.personName;
$w("#dropdown1").value = itemData.designation;
$w("#input16").value = itemData.personPhone01;
$w("#input18").value = itemData.personalWhatsApp01;
$w("#input17").value = itemData.personalEmailText;
$w("#dropdown2").value = itemData.gender;
$w("#input19").value = itemData.website01;
$w("#input26").value = itemData.description;
idToUpdate = itemData._id;
}
// Declaring Item to update function
const updateItem = () => {
// let toUpdate = {
// "_id": idToUpdate,
// "personName": $w("#input15").value,
// "designation": $w("#dropdown1").value,
// "personPhone01": $w("#input16").value,
// "personalWhatsApp01": $w("#input18").value,
// "personalEmailText": $w("#input17").value,
// "gender": $w("#dropdown2").value,
// "website01": $w("#input19").value,
// };
wixData.get(myCollection, idToUpdate)
.then((item)=>{
let toUpdate = item;
toUpdate.personName = $w("#input15").value;
toUpdate.designation = $w("#dropdown1").value;
toUpdate.personPhone01 = $w("#input16").value;
toUpdate.personalWhatsApp01 = $w("#input18").value;
toUpdate.personalEmailText = $w("#input17").value;
toUpdate.gender = $w("#dropdown2").value;
toUpdate.website01 = $w("#input19").value;
toUpdate.description = $w("#input26").value;
wixData.update(myCollection, toUpdate)
.then((results) => {
console.log(results); //see item below
})
.catch((err) => {
console.log(err);
});
})
}
// Populating fields with a button click (unnecessary but following the code)
$w("#button443").onClick(($item, itemData, index)=>{
$item("item").onClick()
})
// Submitting the values to dataset
$w("#button20").onClick(updateItem);
//...
/* item is:
*
* {
* "_id": "00001",
* "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
* "_createdDate": "2017-05-24T12:33:18.938Z",
* "_updatedDate": "2017-05-24T12:33:18.938Z",
* "title": "Mr.",
* "first_name": "John",
* "last_name": "Doe"
* }
*Appreciate any help. Thanks in advance.
Prashant
Hi Prashant,
There are several possible issues with your code: 1. There is a syntax error:
2. The params in the onClick function are inccorrect:
$w("#button443").onClick(($item, itemData, index)=>{ $item("item").onClick() }) //This is a mix between onClick and a repeater onItemReadyThere may be other issues - I would recommend cleaning up the code and removing all code that is commented out. Best, Eitan