Page 1 of 1

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

Posted: Fri Nov 29, 2013 9:06 pm
by John Rodwell

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.


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

Posted: Fri Nov 29, 2013 9:49 pm
by Maryna Brodina

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


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

Posted: Mon Dec 02, 2013 10:21 pm
by John Rodwell

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


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

Posted: Tue Dec 03, 2013 9:13 am
by Maryna Brodina

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


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

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

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?


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

Posted: Sun Aug 03, 2014 11:09 pm
by Yurii Orishchuk

Hi Alex,

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

Regards.


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

Posted: Mon Nov 24, 2014 2:52 am
by Ellen Schlechter

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.


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

Posted: Mon Nov 24, 2014 4:06 pm
by Maryna Brodina

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.


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

Posted: Tue Nov 25, 2014 4:21 am
by Ellen Schlechter

Thanks :)