Page 1 of 1

Using local storage for item selected from a list

Posted: Sat Jul 11, 2015 5:36 pm
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


Using local storage for item selected from a list

Posted: Sat Jul 11, 2015 7:12 pm
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


Using local storage for item selected from a list

Posted: Sat Jul 11, 2015 9:23 pm
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.


Using local storage for item selected from a list

Posted: Mon Jul 13, 2015 1:58 am
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.