facebook

Update SelectListMenu from Local Storage – CLOSED

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #345544 Reply

    Code_A
    Member

    I 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!

    #345563

    Code_A
    Member

    Can 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.

    #345567

    Unknown Author
    Participant

    This 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);
    
    
    #345568

    Code_A
    Member

    Thank 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.

    #345605

    Code_A
    Member

    I 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.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Update SelectListMenu from Local Storage – CLOSED

You must be logged in to post in the forum log in