Textbox in the repeater is connected to database showing items.I want to send that item to another database .My code is sending data but not what item it is showing.Please help me ,I am new in coding.MY Code:
import wixData from 'wix-data';
var item;
$w.onReady(function () {
//TODO: write your page related code here...
item = $w("#text2").text;
});
export function button1_onclick() {
//Add your code for this event here:;
wixData.insert('wishlist', {test1:item});}
Hi,
Can you please open a new thread regarding the new issues?
Roi.
I have the same question.
Should I collect the filtered data from the repeater or from the original collection to another database?
Thanks Roi! It works!
I have another question regarding repeaters.
I have already added a filter to my repeater, how can I send all filtered data to another database?
Thank you.
Cheers,
Ben
Hi,
Just add it to the toInsert object, Make sure it matches to the fieldkey in the database
let toInsert = { CustomerName: $w("#text1").text, Country: $w("#text2").text, City: $w("#text3").text, fieldkey: $w('staticDataInPage').value, anotherFieldkey: $w('anotherStaticDataInPage').value, };
Good luck!
Roi.
Hi Roi,
Thanks for your code. I have successfully implemented it!
How can I submit other static fields from the page into the same entry in the same database (wishlist)?
For example,
let toInsert = {
"CustomerName" : $w("#text1").text,
"Country" : $w("#text2").text,
"City" : $w("#text3").text,
};
wixData.insert("wishlist", toInsert)
.then( (results) => {
let item = results;
} )
.catch( (err) => {
let errorMsg = err;
} );
}
Thanks.
Ben
Hi Roi,
Thanks for the Reply.
I try to work with your code but as I am new to coding,can get anything from it and it is not working for my problem.
Here I have a repeater and I want to get the item (showing in the text box which is connected to the menu database) and save the item name in the textbox to another database on the click of the button in the repeater.
Hi,
I like you way, I have another suggestion.
Here is a code sample.
Note the comments
import wixData from 'wix-data'; import wixUsers from 'wix-users'; export function button1_click(event, $w) { const user = wixUsers.currentUser; const userId = user.id; const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater. wixData.query("yourDatabaseCollection") // get the item from the database collection. .eq("_id", itemId) .find() .then((results) => { const itemToWishlist = results.items[0]; itemToWishlist.userId = userId; // adding a field of the current user to the database in order to distinguish between other users wishlist. wixData.insert("wishlist", itemToWishlist) // finally, insert it to the wishlish database collection. .then(() => { console.log('Done') }); }); }
Good luck!
Roi