I need to send some data to my ‘Comunidad’ collection. Upon hitting the submit button I need to capture the member ID, profile image, and username which are located in my ‘Afiliados’ collection. Also, I have a text box for comments set up but when I click the submit button three different rows are created in the collection, two rows for ID, profile image, and username, and another one for the comment. I don’t need three different rows to be created I need everything to go to the same row. Does anyone have a solution for this?
You currently have three separate form submit actions.
If you will load the page without clicking the submit button you will notice that your collection was already updated, this happens since code written in the onReady event is executed once the page was loaded.
You need to combine the three form inserts into one event, such as a click on the submit button.
Disconnect the submit button from the dataset ‘submit’ action, and add a onClick event from the properties panel.
This will automatically add the onClick event to your code panel.
Then copy and paste the relevant code from the onReady event, and use $w(‘#inputName’).value to get the fields from the input form.
//... After the results from the Afiliados query returned:
wixData.insert('Comunidad',{
'nombreDeUsuario':item.nombreDeUsuario,
'someField': $w('#someInput').value,
'otherField': $w('#otherInput').value,
//and so on and so fourth...
'imageUrl':item.image,
'title':item._id});
Yesterday I go my issue to work - but I guess it didn’t get saved. Today I can’t get it, after many tries using various coding. I’m stopping here for the moment.
What I have is an input file with a dropdown which chooses a value from dataset (TypeUsed) for a reference field in another dataset (A-UsedItems)
The Code
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from ‘wix-data’;
$w.onReady(function () {
//TODO: write your page related code here…
});
export function dropdown6_change(event, $w) {
// Query drom dropdwon change event
wixData.query(“TypeUsed”)
.eq(“title”, $w(“#dropdown6”).value)
.find()
.then( (results) => {
let firstItem = results.items[0];
$w(“#text26”).text = $w(“#dropdown6”).value; // simply to confirm
let toinsert ={
“A-UsedItems”: firstItem,
“usedType”: $w(“#dropdown6”).value
};
wixData.insert("A-UsedItems",{"usedType": $w("#dropdown6").value})
.then ((results) => {
let item = results[0];
} )
.catch( (err) => {
let errorMsg = err;
} );
} );
}
When I run this on its page and submit it submits OK? but the inserted value is place on another record though it doesn't show the value just that something was put there.
It comes up with reference broken?
The other thing I can’t figure out is that the page will not submit until I load an Image and it does care which one of the 6 Images and the images are not required ( only 2 fields are required and they show red and are filled?
Hi, well I’m facing the same issue. In my case, i have a button that calculates two numeric fields entered by a user when he/she fills the form. I have insert the calculated field into the database with wixData.insert, but when i submit the form, it creates a whole new empty record. My code is off the onReady event. I know WHY this happens (when i calculate the fields, the code insert the new data to database and takes it as a record and when i submit the form, it creates a new), but I dont know the way to solve it.
So, i want to submit the form with the new calculated data in the field, having this field in the same record. So the submission mail will contain this calculated field. Can anyone help me plz ?