- This topic has 14 replies, 2 voices, and was last updated 12 years, 4 months ago by
support-octavio.
-
AuthorPosts
-
mreadeMemberSupport
How can one retain the app settings upon closing the app so the same settings can be used once the app is started another time.
Thanks in advance.
support-octavioMemberHi mreade,
Can you tell me what settings are you referring? if you want to keep data for the next time that you open the app, you could use localStorage: http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=2251
mreadeMemberOctavio,
I have a combobox on page1 called (units) with two items (Imperial and metric) with Imperial being the first item on the list.
If users were to select metric, I would like for app to start in the metric calculation mode
, not imperial and/or vice versa.Thanks in advance.
mreade
support-octavioMemberHi mreade,
You can save in localStorage the value of selected value in combobox in the onChange action with next snippet code:
$('select[name="combobox1"] option[value="value5"]').attr('selected','selected') phoneui.preprocessDOM('#m1-combo_localStorage');
Then in phoneui.readyHandler function use next code to retrieve the value saved in localStorage and update the combobox selected value:
var cmbLastVal = localStorage.getItem("val"); $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected') phoneui.preprocessDOM('#m1-combo_localStorage');
mreadeMemberThanks Octavio,
I am currently away and will give this a try next week, then let you know how I make out.
Thanks
mreade
mreadeMemberOctavio,
I am just returning from being on the road for a week and I am going to try to implement localstorage into my app.
However, I do have a few questions about the code snippet you posted on this matter.
IN the first code snippet you indicated a “value5”. I am not sure what you are referring to with this code? In my combo list I have two items such as:
Label Value Selected
US (Imperial) imperial Yes
SI (Metric) metric NoThe name of my combo list on the frmMain.mobi page has an ID of “units.”
I tried the code you provide and I was not able to restart the app with the last combobox selection.
Any suggestions?
Thanks
mreade
support-octavioMemberHi mreade,
Seems that I goofed up with my copy/paste code when I did a quick design to achieve this request. My apologies.
The code for the onclick change should be this:
localStorage.setItem("val",$('select[name="combobox1"]').val());
Note that “val” is the key for the saved value.
That value will be pulled with the second code I posted last time:
var cmbLastVal = localStorage.getItem("val"); $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected') phoneui.preprocessDOM('#m1-combo_localStorage');
mreadeMemberThanks Octavio,
I will give the a try and advise.
mreade
mreadeMemberOctavio,
OK, it seems as though the last code snippet you suggests will store the combolist’s last selection (i.e.: imperial, or metric)
Although the app will start with the proper combolist value selected (checked), the combolist widget shows the first item on the list. For example,
I have two items on the list:
1. US (Imperial) (which has a value of “imperial”)
2. SI (Metric) (which has a value of “metric”)Upon starting the app, the default “imperial” values is selected and the US (Imperial) is showing in the combolist widget.
I’ve selected the “metric” value to continue with metric calculations. That works fine. I close the app on my iPhone and upon restarting the app, although “metric” was the last selected item on the combolist, the US (Imperial) is still showing upon startup. As I open the combolist the SI (Metric) is checked so it looks like the proper item (value) is stored locally.
Question:
How can i get the app to also show the proper combolist item upon startup. For example:
if “imperial” is the localstored value, show US (Imperial) upon startup, or if “metric” is the localstored value, show SI (Metric) upon startup.
I hope this makes sense.
Thanks
mreade
mreadeMemberSupport,
Any suggestions how i can get the app to show the proper combobox item upon startup after recalling the localstorage value?
Thanks
mreade
support-octavioMemberQ: Did you put the code that I suggest you to use in phoneui.documentReadyHandler function?
@support-octavio wrote:
Then in phoneui.readyHandler function use next code to retrieve the value saved in localStorage and update the combobox selected value:
var cmbLastVal = localStorage.getItem("val"); $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected') phoneui.preprocessDOM('#m1-combo_localStorage');
In case you did and is not working, could you attach your .mobi file and custom.js to take a look?
mreadeMemberThank you, I will email a zip file containing the information.
mreade
mreadeMemberSupport,
I have just finished emailing you a zip file with the .mobi form and _custom.js script file.
mreade
mreadeMemberOctavio,
Your suggestion of making a slight code change in the preprocessDOM snippet to reflect the form name and not the code in your snippet has corrected the problem with the combobox list not showing the proper list item upon starting.
Now, when the app starts, it does show the proper combolist item.
Thanks, problem solved.
mreade
support-octavioMemberHi mreade,
Glad to know that all is working fine. Thanks for your follow up. Thread Closed.
-
AuthorPosts