Using local storage for item selected from a list

This forum contains topics that were moved from Get Satisfaction
Jeff Salter
Posts: 0
Joined: Sun Jul 05, 2015 2:30 pm

Using local storage for item selected from a list

Post by Jeff Salter »

I have a list box that shows name and number from a database. ( I tried to simplify by taking off name for testing)
User can select multiple itmes
How do I determine which were clicked, save those numbers?
I've tried numerous solutions but the closest I have come is using this:

var checked =[];
Apperyio("mobilecheckboxgroup_12").find("input:checked").each(function(){
checked.push($(this).attr('mobileNumber'));
});
localStorage.setItem("messages", JSON.stringify(checked));

I don't know if my problem has to do with mapping or something else?

Image Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Using local storage for item selected from a list

Post by Illya Stepanov »

Hi Jeff -

Your question is related to jQuery, you can search online how to work with this framework and solve common problems or search on our forum, most such cases have been covered previously.

Here is an example which uses checkboxes components and store selected values in local storage:
pre
code
//Where "mobilecheckboxgroup_23" your checkboxesgroup name. You should replace it with yours.

var checkBoxes = Apperyio("mobilecheckboxgroup_23").find('input[type="checkbox"]');
var checkBoxesState = {};

for(var i = 0; i < checkBoxes&#46;length; i++){
var checkBox = jQuery(checkBoxes);

Code: Select all

 checkBoxesState[checkBox&#46;val()] = {checked: checkBox&#46;prop("checked"), view: checkBox&#46;closest("&#46;ui-checkbox")&#46;find("label")&#46;text()}; 

};

console&#46;log(checkBoxesState);

&#47;&#47;Store checkboxes state to the local storage variable&#46;

localStorage&#46;setItem("checkBoxesState", JSON&#46;stringify(checkBoxesState) );
/code
/pre

Jeff Salter
Posts: 0
Joined: Sun Jul 05, 2015 2:30 pm

Using local storage for item selected from a list

Post by Jeff Salter »

I've looked at many of the examples and there seems to be a number of different solutions to this. I wish someone would record a video on it since it seems to be a common issue here. I tried this example but it only gives me back the label and not the value in the label. I've spent a ridiculous amount of time trying to figure out this last issue to get my app to work right.

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

Using local storage for item selected from a list

Post by Yurii Orishchuk »

Hi Jeff,

Just tried this code and it works correctly.

See more details on the screen shot:

http://prntscr.com/7s00o9/direct

Regards.

Post Reply