Hello,
I’m very new to this.
I have a dynamic page which pulls data from dataset A.
Also I have few text-input fields, which I submit with a button to another dataset, B.
Basically I want to know on which dynamically pulled item from dataset A, the user was at the time of submission.
Please point me out to where to look for.
Greatly appreciate.
Are trying to get the current item ??
#dynamicDataset - dynamic dataset
let currentItem = $w("#dynamicDataset").getCurrentItem();
Yes, thanks, the current item.
I’ve seen this piece of code. But can’t figure where to put it so when a user clicks a button, this value goes to another dataset’s certain column.
Yeah !
You haven’t provided your database fields, so I put here an example…
So here’s what you are trying to do →
When a user clicks a button, the current value (from the database A ) should be inserted to database B…
If so →
#button1 - button
#dynamicDataset - dynamic dataset
Database B field - ‘title’
Database A field - ‘info’
info - (Database B) it is the field in which the value would be inserted from Database A
title - Database A’s field to get the current item
$w.onReady(function () {
$w('#button1').onClick((event) => {
let currentItem = $w('#dynamicDataset').getCurrentItem().title;
let toInsert = {
"info" : currentItem
};
wixData.insert("DatabaseB", toInsert);
});
});
Hi!
I’m trying to do the same thing, but when I use your code @Ajit Kumar it says that “wixData” is not defined. Do you know how to define this function?
@scwaalbers Yeah!!! paste this code in to very top of all your code →
import wixData from'wix-data';
@ajithkrr
I’m not very sure where to add this code to.
Will the entry will be within a transaction with other text-input field per click?
Meaning some fields of the entry will be from the screen, though some will be pulled from Database A.
Do I add it to button event somewhere?
@bobargo1 Are you referring to ->???
import wixData from'wix-data';
Thanks for the quick reply! However it’s still not working I tried debugging using the console but it’ll just tell me that my #dataset1 is non existent.
When I hover over the dataset I want to alter in the editor, it does say that its called #dataset1
@scwaalbers can you post your code or upload the dataset
Thanks, it worked, but…
I connected few input-fields to be submitted via interface.
Then I added the code you gave.
Result: I have two rows added to my Database.
Is there a way to make it so only one row gets added to the DB on mouse click?
Thanks anyway man, really helpful.
For the code to work properly, just remove the connection from the input through the dataset in the EDITOR
@ajithkrr Thanks! it turned out that the dataset was called something different in the end