facebook

Populate SelectListMenu on start up

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

    jankt
    Member

    I have been using MobiOne for a copuple of weejs now, and I think it is a fantastick product.
    Being a novice, I am not always familiar with the proper syntax, and have to seek help in some of the very good examples.
    In this case, I haven’t been able find any solution, so I now try to see if this post can help me:

    I have an app, which has a SelectListMenu. This is placed on my Configuration Screen.

    In the above sample I have selected the item “Minimix”
    On the configuration screen, I have a “Save” button that saves all field values to local storage.

    I have another function that is called during start up, which populates the fields with data from local storage.
    I am able to populate all fields – except my SelectListMenu.

    I have tried to preset my SelectListMenu using the following statement (with no luck):

    $(‘#m1-SportStat_Main-selectListDeptMenu’).val(cUserDepartment);
    ‘cUserDepartment’ is the variable for which I have retrieved the data from local storage.

    So my question is how do you preset a SelectListMenu with a predefined value (list item selected)?
    Any help on this will be much appreciated.

    #340684 Reply

    Stu Wade
    Member

    Do you not need to set the value of the selectlistmenuitem rather than that of the menu itself?

    Certainly this is the case for a selectlist, I have done this successfully, never actually used the menu widget.

    #340687 Reply

    jankt
    Member

    Hi Stu

    Thanks for the response and sorry for not being precise.

    What I am really trying to achieve is:

    Select a value from my list, in the sample below it is “U14 Piger”.

    This value I am saving in local storage and the next time my app starts, I need to read that value in order to “preset” the list to the last value stored (“U14 Piger”)

    Hope this explains it 🙂

    Regards
    Jan

    #340693 Reply

    benl
    Member

    I do something similar:

    This code selects the value in the list (you could easily replace yourstoragevalue with your storage retrieval string or set a variable equal to the storage value):

    
    $("#m1-screen_id-hidden-select-selectName").find('option[value="' +  yourstoragevalue + '"]').attr("selected",true);
    

    This code updates the value the main form/field based off of the selected option:

    
    $("#m1-screen_id-selectName-selinfo").text($("#m1-screen_id-hidden-select-select_id").find('option:selected').text());
    
    #340704 Reply

    jankt
    Member

    Hi benl

    Great – this was exactly what I needed to get started. Thanks!

    My code can probably be tuned further, but I now have the functionality that I need and I have learned a lot from this post 🙂
    I ended up using the following code, where cUserDepartment is my local storage variable.

    
    // get label/text of the "default" selected item in selectListDeptMenu
    var default_value = $('select[name="selectListDeptMenu"]').val();
    
    // Deselect Default selected value
    $("#m1-SportStat_Main-hidden-select-selectListDeptMenu").find('option[value="' +  default_value + '"]').attr("selected",false);
    
    // Select the saved value from local storage
    $("#m1-SportStat_Main-hidden-select-selectListDeptMenu").find('option[value="' +  cUserDepartment + '"]').attr("selected",true);
    
    // Update List
    $("#m1-SportStat_Main-selectListDeptMenu-selinfo").text($("#m1-SportStat_Main-hidden-select-selectListDeptMenu").find('option:selected').text());    
    

    Best regards
    Jan

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Populate SelectListMenu on start up

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