I would like to save a record in a collection with the combination of a text field and a date field in the _id field.
Both following syntax don’t work:
“_id”: $w(“#input9”).value + $w(“#datePicker1”).value,
“_id”: $w(“#input9”).value + toString( $w(“#datePicker1”).value),
How I can get the string value of the date field?
Hi,
The id field has to be unique, and its automatically generated by wix each time new record inserted. if you want to make your own id ( I dont recomend your combination for the id because there is a chance it will not be unique and ID is usually unique for each record ), create new field then it should work. So, your code should look something like this :
export function button(event) {
let x = $w("#input").value;
let y = $w("#datePicker").value;
let toInsert = {
"title": x + y
};
wixData.insert("datasetName", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
Hope this helps!
Best,
Mustafa
Thank’s for your help. I will try it because I’m on a study stage of WIX capabilities and I’m curious to see if WIX allows “+” operator on fields originating from different types.
Actually, I must have a unique key, but I need to be able to know what the key is, in order to retrieve the data in others forms, reports, etc… in later stages.
On the meantime, I founded the below similar solution and it’s work:
“_id”: $w(“#input1”).value + Date.parse($w(“#datePicker1”).value),
Thank You.