Database - repeater autosave when edit data in textbox?

Hi
How can i make it so that visitors newly entered data in a textbox is autosaved when the user goes to a new textbox in a repeater. Each row in the repeater represent a row in my database. I have a textbox so the user can update some values in the database.

Only solution to save the data that i have found is to add a submit button to each row in the repeater. I really want to have an autosave. Something like this: when user exit textbox, save value to database. OR when user make change to textbox, save value to database. So that the users latest input is always the data that is stored.

I have tried to make this work by adding this code.
$w(‘#dataset1’).save()
i have placed this code in the onChange, onBlur, onClick functions of the textbox but nothing gets saved.

screenshots:

Link to my edit of the site: https://editor.wix.com/html/editor/web/renderer/edit/6829c53e-13c8-4435-8422-f9123d87be29?metaSiteId=4647b62d-d504-4fad-b62e-fbc7f65955ce&editorSessionId=6c3fb74a-04f2-4d64-b525-c7738e700750&referralInfo=dashboard

Hej
Is the textbox added within the repeater then you must add the onBlur event in the onItemReady or forEachItem loop using the repeater. Adding an outside event handler won’t work inside a repeater. Please send in some code and I will have a look at it.

Ses online snart :slight_smile:

Not sure what you mean… im not very good with this code.

I have now added the onBlur event in the onItemReady event.

export function repeater1_itemReady($item, itemData, index) {
//Add your code for this event here:

function input1_blur(event) {
//Add your code for this event here:
$w(‘#dataset1’).save()

} 

}

Testing this and nothing happens. No error messages and save does not work.
No clue about that lopp thing.

i used code below and it works . try with repeator because it was on page and maybe needs to be change a little. When You use save i think You have to setfieldvalue brfore save with code.

export function yourtextfield_blur(event) {
$w(‘#dataset1’).onReady(() => {
let imiemlo = $w(“#yourtextfield”).value;
$w(“#dataset1”).setFieldValue(“imie”, imiemlo);
$w(“#dataset1”).save();

})

Now i get this error:
http://prntscr.com/lrt8m1

I put the code on page.

check brackets. Should be the same ( like ) if something is opened should be also closed. If you go on page on bracket it shows you where is other. It means add one more }

well i cant find an open bracket
it seems like everything checks out, but im sure im just blind and miss something

export function input1_blur(event) {
$w(‘#dataset1’).onReady(() => {
let imiemlo = $w(“#input1”).value;
$w(“#dataset1”).setFieldValue(“imie”, imiemlo);
$w(“#dataset1”).save();

})

Think i fixed it.

export function input1_blur(event) { $w(’ #dataset1 ').onReady(() => { let imiemlo = $w(" #input1 “).value; $w(” #dataset1 “).setFieldValue(“imie”, imiemlo); $w(” #dataset1 ").save(); })}

But the save function still does not work.
The repeater still does not save data when data is enterd in the textbox. still requiers to press a submit button fo the data to save.

Did You changed names of dataset and input, and field “imie” into Your fieldname. ?

I missed that “imie” should be my field name?
By fieldname i guess you are telling me the name of the textbox where the user are inserting new data?

Dataset1 = my dataset on that page
input1 = textbox where the user insert new data

what else am i missing. this code does not work still

export function input1_blur(event) {
$w(‘#dataset1’).onReady(() => {
let imiemlo = $w(“#input1”).value;
$w(“#dataset1”).setFieldValue(“input1”, imiemlo);
$w(“#dataset1”).save();

}) 

}

screenshot:

$w(" #dataset1 ").setFieldValue(“input1”, imiemlo);

“input1” its not input but place in collecion where it should be saved. So find in collection Filed key where You want to save value of input

Well now i have changed the code to that.
Still does not work.
Here is my filed key wehre i want to save the data in the collection

It is a number column and the texbox (input1) is set to number on the site.

And then i have this code on the page.

export function input1_blur(event) {
$w(‘#dataset1’).onReady(() => {
let imiemlo = $w(“#input1”).value;
$w(“#dataset1”).setFieldValue(“inventeringsvarde”, imiemlo);
$w(“#dataset1”).save();

}) 

}

screenshot: Screenshot by Lightshot

Nothing gets saved when data is updated in the textbox on the site.

EDIT:
I have also tried to put #inventeringsvarde in the collection location. this does not work either.

in properties input 1 click on onBlur and add it again in code panel betwean {}. ON blur means when You go out of input. See if in panel something happens. Check if collecion and dataset in properties can be written or is read only

 $w(' [#dataset1](https://www.wix.com/code/home/forum/search/posts%3Fquery=.num.dataset1) ').onReady(() => {   let  imiemlo = $w(" [#input1](https://www.wix.com/code/home/forum/search/posts%3Fquery=.num.input1) ").value;         $w(" [#dataset1](https://www.wix.com/code/home/forum/search/posts%3Fquery=.num.dataset1) ").setFieldValue("inventeringsvarde", imiemlo);         $w(" [#dataset1](https://www.wix.com/code/home/forum/search/posts%3Fquery=.num.dataset1) ").save();      })

I got the code to work now, but not as expected…
When i update the top textobx, it is just set to 0. I type a value and exit the textobx and that value is deleted and changed to a zero.

probably because You have connected input to dataset1 i editor. Wen You have own code it doesnt need to be connected i think. Try to disconnect input and try again.

Now disconnected.
like this: http://prntscr.com/lsajoi

Still nothing is saved to the database.
Now the top row in the repeater do nothing, if i put back the connection the top row atleast reacts to something by automatically becoming a zero when edited.

ehat is toptextbox and what it update please write or printscreen

Here is a video: https://streamable.com/4ntzk
Top textbox = first textbox in the repeater

ok i missed its in repeator so i think code should know where you are in which repetor You are. I will try and write You code

try this. dont forget $w after event.

export function input1_blur(event, $w) {

let $item = $w.at(event.context);
let imiemlo = $item(“#input3”).value;
$w(‘#dataset1’).setFieldValue(" inventeringsvarde ", imiemlo)

return $w(“#dataset1”).save();

}