Hi,
I have a multi-state box and in every state there is a form, build with Wix Forms, but with custom submit buttons that “collect” the inputs from all forms, and at the last form there is a submit button to insert it into the database, using wixData.
When I filled the form and submit, everything worked and the input saved into the table, but when I tried it again I got an error: “an item with _id [XXXXXX-XXX-XXX] already exists”.
The _id is the same _id of the previous insert.
When I reload the page it’s worked, but again, only for the first time.
I checked that the primary key is different of course.
This is the submit function:
export function back2Button_click(event) {
wixData.insert("ConsultationTable", toInsert)
.then( (results) => {
let item = results;
resetForm();
} )
.catch( (err) => {
let errorMsg = err;
} );
}
‘toInsert’ is the object that contains the inputs.
‘resetForm()’ is function to reset the forms (clear textboxes, uncheck checkboxes and so on:
function resetForm() {
$w('#input2').value = '';
$w('#input3').value = '';
$w('#input4').value = '';
$w('#input12').value = '';
$w('#input13').value = '';
$w('#input2').resetValidityIndication();
$w('#input13').resetValidityIndication();
const textinputList = $w('TextInput');
textinputList.forEach(element => {
element.checked = false;
});
$w('#input19').value = '';
$w('#input20').value = '';
$w('#input21').value = '';
$w('#input22').value = '';
$w('#input23').value = '';
if (formFactor === "Desktop") {
$w('#input19').hide();
$w('#input20').hide();
$w('#input21').hide();
$w('#input22').hide();
$w('#input23').hide();
} else {
$w('#input19').collapse();
$w('#input20').collapse();
$w('#input21').collapse();
$w('#input22').collapse();
$w('#input23').collapse();
}
$w('#textBox1').value = '';
$w('#textBox1').collapse();
$w('#datePicker1').value = null;
}
Thank you!