Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

Hi

So I dont understand the "local storage" idea. My app do not require a login but there are some checkboxes that i want to store for that user.

Will local storage do the job?

Thank you

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Storage

Hi Johnny,

Yes, but please please take into account that localStorage stores strings only. That is, you can store "0" and "1" as strings.
The following discussion may be helpful for work with checkboxes: https://getsatisfaction.com/apperyio/...

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

Thank you :) yes I saw the little that I read that they also say that. Thank you again!

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

can I use this code below in a app? I dont get it to work. Sorry for dumb question!
Checkbox 1
Checkbox 2
Checkbox 3
Checkbox 4
Checkbox 5


SAVE

LOAD
var i, checkboxes = document.querySelectorAll('input[type=checkbox]');

function save() {
for (i = 0; i < checkboxes.length; i++) {
localStorage.setItem(checkboxes.value, checkboxes.checked);
}
}

function load_() {
for (i = 0; i < checkboxes.length; i++) {
checkboxes.checked = localStorage.getItem(checkboxes.value) === 'true' ? true:false;
}
}
http://jsfiddle.net/sQuEy/4/

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

Sorry the code I paste did not show but it is on the link

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Storage

Hello! You can use < code tag to post your code. You would also need to explain in more details where do you use this code, what are you trying to acheive and what exactly doesn't work?
http://docs.appery.io/getting-help/

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

ok, i still want to do just a simple save and load on the app. Save a checkboxs value and get it when the app is loading. This is my first app and just starting to get use to the all the java script.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Storage

Your code saves checkboxed on all loaded screens and uses checkbox value for localStorage variable name (there might be problem if checkbox values are the same). To save use the following code:
codevar checked = [];
Appery("mobilecheckboxgroupName")&#46;find("input:checked")&#46;each(function(){
checked&#46;push($(this)&#46;attr("id"));
});
localStorage&#46;setItem("mobilecheckboxgroupName_checked", JSON&#46;stringify(checked));/code
to get:
codevar checked, i, len;
Appery("mobilecheckboxgroupName")&#46;find("input")&#46;each(function () {$(this)&#46;prop("checked", false);});
try {
checked = JSON&#46;parse(localStorage&#46;getItem("mobilecheckboxgroupName_checked"));
if ({}&#46;toString&#46;call(checked) !== "[object Array]") {
checked = [];
}
} catch ( e ) {
checked = [];
}
for (i = 0, len = checked&#46;length; i < len; i++) {
try {
$("#" + checked)&#46;prop("checked", true);
} catch ( e ) {
}
}
Appery("mobilecheckboxgroupName")&#46;find("input")&#46;each(function () {$(this)&#46;checkboxradio("refresh");});/code
where mobilecheckboxgroupName - mobilecheckboxgroup name

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

Wow thank you so much!! I really appreciate the help!

Johnny
Posts: 0
Joined: Tue Jul 23, 2013 10:09 am

Storage

Just some feedback! The code is working beautifully thank you for the help!

Return to “Issues”