Hey guys,
Having a bit of a mind blank on this one.
Here is the current issue, I have a value that is assigned via corvid code, which checks the days of two date ranges.
This is then assigned a value to one of the text fields which I then want to insert into my dataset.
However on my dataset its always blank, UNLESS i enter smething in this field manually, which I dont want to do as ideally this text field that has this generated number will be hidden.
Below is my code, perhaps I have done something silly, or does this not work like that?
export function uploadButton1_change(event) {
//Add your code for this event here:
let date1 = $w("#datePicker1").value;
let date2 = $w("#datePicker2").value;
let diffdays = date_diff_indays(date1, date2);
$w("#input4").value = diffdays;
$w("#diffdays").text = diffdays.toValue();
console.log(diffdays);
}
I have a submit button that submits all the data in the form, or because this is a corvid assigned variable do I need to set up for the whole form to be inserted via corvid also?
Hello.
Yes, you need to insert your data to your database collection via code. You can use data insert function to do this.
Good luck!
Have tried via code also.
Same issue.
Tried with a hardcoded value like below and also with the value being grabbed from the above calculation.
Still enters blanks.
export function button1_click(event, $w) {
//Add your code for this event here:
let toInsert = {
"daysSincePurchase": "8"
};
wixData.insert("UserToolRegistration", toInsert)
.then ( (results) => {
let item = results;
console.log("Inserted");
} )
.catch( (err) => {
let errorMsg = err;
console.log("Failed");
});
}
You will need to provide more information. Does “Inserted” or “Failed” get printed in the console?
What are the permissions of your database collection? Make sure they’re set to “Form Submission”, or some other permission that allows a user to write to the collection.
Is the field “daysSincePurchase” a text field or a number field? If it’s a number field, then you will need to use a number (e.g. 8) and not a string (“8”).
Says failed in the console.
Database permissions are site member author as the rest of the information gets inserted.
DaysSincePurchase is a text field type in my dataset.