John Rodwell
Posts: 0
Joined: Sun Nov 24, 2013 11:51 pm

How to keep checkboxes checked or unchecked after exiting browser and returning.

I need to be able to enable checkboxes to remain in view - checked or unchecked after someone has exited the browser, then returned. I have used the 'Hello World' tutorial for saving entered textbox input, but I can't get the same kind of process to work for checkboxes. Is there a tutorial to help me do this, or can you offer any guidance. I am new to appery.io so as much detail as possible will be appreciated. Many thanks John.

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

How to keep checkboxes checked or unchecked after exiting browser and returning.

Hello! Save checked checkboxes into localStorage. On page Show restore them from localStorage. To save prevar checked = [];
Appery("mobilecheckboxgroupName").find("input:checked").each(function(){
checked.push($(this).attr("value"));
});
localStorage.setItem("mobilecheckboxgroupName_checked", JSON.stringify(checked));/pre to restore prevar checked, i, len;
Appery("mobilecheckboxgroupName").find("input").each(function () {$(this).prop("checked", false).checkboxradio("refresh");});
try {
checked = JSON.parse(localStorage.getItem("mobilecheckboxgroupName_checked"));
if ({}.toString.call(checked) !== "[object Array]") {
checked = [];
}
} catch ( e ) {
checked = [];
}
for (i = 0, len = checked&#46;length; i < len; i++) {
try {
Appery("mobilecheckboxgroupName")&#46;find("input[value='" + checked + "']")&#46;prop("checked", true)&#46;checkboxradio("refresh");
} catch ( e ) {
}
}/pre

John Rodwell
Posts: 0
Joined: Sun Nov 24, 2013 11:51 pm

How to keep checkboxes checked or unchecked after exiting browser and returning.

Thank you Maryna!

With some additional support from Igor Moroz, I eventually got this to work.

Is it possible for you to provide similar scripts in order to keep the selection from a select / drop-down menu in view after exiting the browser?

I hope this will be my last request for this kind of support. If I can get this to work as well, my next step will be to sign up for an Appery.io package and finalise my app.

Thanks again,
John

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

How to keep checkboxes checked or unchecked after exiting browser and returning.

Hello! To save selected value into localStorage you can use Value change event and Set local storage variable action, or the following code prelocalStorage&#46;setItem("varName", Appery("selectName")&#46;val());/pre and to restore on page Show prevar $select = Appery("selectName");
$select&#46;find('option[value="' + localStorage&#46;getItem("varName") + '"]')&#46;attr("selected", true);
$select&#46;selectmenu("refresh");/pre

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

How to keep checkboxes checked or unchecked after exiting browser and returning.

are the "varName" and "selectName" related to the checkboxgroup or the checkboxes that are changing?

is varName the same as mobilecheckboxgroupName_checked?
is selectName the same as checkboxgroup?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to keep checkboxes checked or unchecked after exiting browser and returning.

Hi Alex,

Marynas comment relates only to "select" component not to checkbox component.

Regards.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to keep checkboxes checked or unchecked after exiting browser and returning.

What if I want it saved on a user's account and not on the device so that no matter what device you check a box on, it shows up on another signed into the account?

For instance, users use my app to create items with multiple fields. I want them to be able to check a box so that they can pick what fields they see so that the others aren't in the way.

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

How to keep checkboxes checked or unchecked after exiting browser and returning.

Hello!

To make it work use DB.
1) Add one more DB column with boolean type.
2) On every check box value change event save value to DB for current user.

Return to “Issues”