I have a very large form and need it to autosave if users exit the browser, I know that I need to use wix local storage, but how do I write the code to save and then check if the user has put anything if they come back and then update it?
- You have a form on your page.
- A member/user fills this form.
- On every change of the form you save the entered DATA into the local-storage.
- User is now able to leave the page and when the user comes back and opens the page again, you load data to every single form-field back again from local-storage.
You will need this 3 CODE-LINES to code it…
import {local} from 'wix-storage';
local.setItem("key", "value");
let value = local.getItem("key");
Wow thank you! But I don’t know what to fill in for “key” or “value” or is that what I literally type. And do I have to type this for each input or do these 3 lines cover everything?
Ok Rosenzweig (sounds german)
i will give you a little example…
import {local} from 'wix-storage';
$w.onReady(()=>{
let input1 = $w('#HereTheIdOfYourInput1').value
let input2 = $w('#HereTheIdOfYourInput2').value
let input3 = $w('#HereTheIdOfYourInput3').value
let input4 = $w('#HereTheIdOfYourInput4').value
//saving...
local.setItem("input1", input1);
local.setItem("input2", input2);
local.setItem("input3", input3);
local.setItem("input4", input4);
//loading...
let value1 = local.getItem("input1");
let value2 = local.getItem("input2");
let value3 = local.getItem("input3");
let value4 = local.getItem("input4");
console.log("VALUE-1 = ", value1)
console.log("VALUE-2 = ", value2)
console.log("VALUE-3 = ", value3)
console.log("VALUE-4 = ", value4)
})
This is just an example! You will have to modify the code by your own needs!
The name is German haha! Thanks a lot, I will try it and let you know how it goes
Hmm it’s not working, I changed the inputs to the ones on my form, but maybe I’m missing something. I’m guessing its the onchange, but what do I put the onchange on?
Ich sehe leider keinen CODE von dir.
You should perhaps show some code, done by you.
@russian-dima the code I did was your code and then all I changed was the input ID for my inputs. Other than that I have no code
@nechemyar
As i already mentioned,