Page 1 of 1

Keeping Checkboxes Checked when user Navigates away from your Page

Posted: Sat Aug 02, 2014 1:12 am
by Alex Van Name

This question is related to code from another user 8 months before this post...

http://gsfn.us/t/4cqzn

I have been trying to apply this code to my project, but I can't seem to get the code to work. The first time the user makes selections this code is applied after the user has made their choices and a SAVE button is pressed. After this SAVE BUTTON click event...this javascript runs...

--------------------------------------------------------------------------------

// Hello! Save checked checkboxes into localStorage. On page Show restore them // from localStorage. To save...

var checked = [];
Appery("checkboxgroup").find("input:checked").each(function(){
checked.push($(this).attr("value"));
});
localStorage.setItem("mobilecheckboxgroupName_checked", JSON.stringify(checked));

//to restore

var j, len;
Appery("checkboxgroup").find("input").each(function () {$(this).prop("checked", false).checkbox("refresh");});
try {
checked = JSON.parse(localStorage.getItem("mobilecheckboxgroupName_checked"));
if ({}.toString.call(checked) !== "[object Array]") {
checked = [];
}
} catch ( e ) {
checked = [];
}
for (j = 0, len = checked.length; j < len; i++) {
try {
Appery("checkboxgroup").find("input[value='" + checked[j] + "']").prop("checked", true).checkbox("refresh");
} catch ( e ) {
}
}

// To save selected value into localStorage you can use Value change event and Set
// local storage variable action, or the following code

localStorage.setItem("mobilecheckboxgroupName_checked", Appery("checkboxgroup").val());

--------------------------------------------------------------------------------

I understand what is above code is doing, but I am not sure if I need to use all the codes (there are 4 parts) to make my app do the same thing.

I have tried this code when the user comes back to the page with checkboxes as an "ON PAGE SHOW" event

------------------------------------------------------------------------------------------------

var $select = Appery("checkboxgroup");

$select.find('option[value="' + localStorage.getItem("mobilecheckboxgroupName_checked") + '"]').attr("selected", true);

$select.selectmenu("refresh");

------------------------------------------------------------------------------------------------

Keeping Checkboxes Checked when user Navigates away from your Page

Posted: Sat Aug 02, 2014 8:31 pm
by Illya Stepanov

Hi Alex,

Could you please explain it with more details?
As it's not clear what would be your use case, what do you want it to be.


Keeping Checkboxes Checked when user Navigates away from your Page

Posted: Tue Sep 16, 2014 12:35 pm
by Kateryna Grynko

Hi Alex,

Did you sort it out?