- This topic has 4 replies, 3 voices, and was last updated 11 years, 12 months ago by
jankt.
-
AuthorPosts
-
janktMemberI 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.July 9, 2013 at 5:19 am #340684
Stu WadeMemberDo 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.
July 9, 2013 at 10:17 am #340687
janktMemberHi 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
JanJuly 9, 2013 at 1:24 pm #340693
benlMemberI 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());
July 10, 2013 at 1:51 am #340704
janktMemberHi 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 -
AuthorPosts