For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 4 replies, 2 voices, and was last updated 12 years, 2 months ago by
Code_A.
-
AuthorPosts
-
Code_AMemberI am trying to auto select the item in my SelectListMenu from local storage upon app startup. I am saving the selected item index upon user selection. This seems like a simple task (and I’m sure it is) but I am having trouble getting it to function properly. Please help.
I followed the example code in this post: viewtopic.php?f=8&t=5818
Here is my save code:
var number= $('select[name="lstNumbers"] :selected').val(); localStorage.setItem("number",number);Here is my update code:
var number =localStorage.getItem("number"); // Select the saved value from local storage $("#m1-Project-hidden-select-lstNumbers").find('option[value="' + number + '"]').attr("selected",true); // Update List -- which to use? //$("#m1-Project-lstNumbers-selinfo").text($("#m1-Project-hidden-select-select_id").find('option:selected').text()); $("#m1-Project-lstNumbers-selinfo").text($("#m1-Project-hidden-select-lstNumbers").find('option:selected').text());Thanks for the help!
December 28, 2013 at 3:26 pm #345563
Code_AMemberCan someone let me know if this the correct way of auto selecting a select list menu item from local storage? I would like to know if I am up against an implementation problem or a bug in the behavior of the select list menu.
I ran into a similar a similar issue when I was having trying to update list items at runtime (see viewtopic.php?f=8&t=6649). Still not sure if this is a bug or not but I couldn’t get anything to work. To work around this one I am completely tearing down the list and rebuilding to get the new list items. Do I need to do the same thing here? All I am trying to do is programmatically select and item. Seems like it should be fairly straightforward.
I do not see any examples of setting the selected item for the select list menu widget in the Widget Reference documentation. Am I missing something?
Thanks for the help.
December 29, 2013 at 10:51 am #345567
Unknown AuthorParticipantThis is what I use. No guarentees it will work for you.
var selListId = 'm1-page_name-list1'; var listName = 'list1'; var key='thing_Im_storing'; var temp = localStorage.getItem(key); var itemToSelect = [temp]; var selId = $('#' + selListId + '> li').each( function (i) { $(this)[i == itemToSelect ? 'addClass' : 'removeClass'](m1Design.css("selected")); }); phoneui.preprocessDOM('#' + selListId);December 29, 2013 at 1:05 pm #345568
Code_AMemberThank you for the reply, but this solution does not appear to work with the Select List Menu.
Am I doing something wrong, or is the Select List Menu buggy or not meant to be used in the way I am trying to use it??? It seems I am running into to nothing but problems trying to programmatically modify the list.
It seems all the solutions are for standalone lists and not the select list menu…is this because it is easier to work with? I could change all my lists to comboboxes to accomplish the same thing but I like the look of the Select List Menu better.
December 30, 2013 at 3:16 pm #345605
Code_AMemberI finally found the correct working code on the forums (viewtopic.php?f=8&t=6192). Sorry, I did not see this on my initial searches.
-
AuthorPosts
