Brian__
Posts: 0
Joined: Tue Sep 03, 2013 11:33 am

Input Fields are being cleared when back button is pressed

I'm working on an app where I have the following issue:

If I press the back button in the app, in order to return to the previous page, the fields are being cleared of their previous values.

I solved this problem by:
a) storing the value of each input component's text property in a local storage variable
b) Putting some logic in the app which causes the text properties of the these input components to be set on page load, according to the local storage variable, ie

screen_91B7_onLoad = page2_onLoad = function() {
...
setText('page2_page2_input1', localStorage.getItem('variableTest'));
...
}

This works but the problem I'm having is that when I press "Test" and launch the app, the input field is being populated with a value from a previous session. E.g. if I typed the string "blah" into the field in a previous session, when I make changes to the app, press "save", and press Test, the input component will have a value of "blah" even though I've started a new session. Is there any way of avoiding this? Note that this only happens in the browser, not on mobile, but I'd like to be able to demo this to the client in browser, if possible, hence the issue.

Also - is there any better way of solving the issue of the pages not retaining their state once the back button is pressed other than by the use of Local Storage Variables?

Many thanks,

Brian

EDIT: I'd really appreciate someone explaining why this is happening at all. Surely once the window is closed, all data from the session - e.g. global variables - will be removed from the Browser's memory. How can they persist when the "test" window is closed and I even clear the Browser's cache???

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Input Fields are being cleared when back button is pressed

We can't reproduce it unfortunately. Input component is not being cleared when Back button is clicked in browser. Please clarify what browser you use and share your app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a (perhaps you have Input Field which you reset with mapping of any REST service).

Brian__
Posts: 0
Joined: Tue Sep 03, 2013 11:33 am

Input Fields are being cleared when back button is pressed

Hi Marina,

Just to be clear on something: The issue occurs when the back button is pressed in the app, not in the browser (I'm using Chrome). To further clarify, I'm referring to the button which appears when you tick the "Back Button" relating to a specific component in the property panel of Appery. When I press this button when testing the app the fields of the input components are cleared once I navigate to the previous page.

I've encountered this in multiple proof-of-concept apps I've developed over the last few days, so am assuming that this is a known issue?

Many thanks,

Brian

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Input Fields are being cleared when back button is pressed

The Back Button is a standard jQuery Mobile back navigation and goes back to the previous browser page (it does history.back(-1)).

There is no special code that we use to handle going back to the previous page. One reason why the values might be clearing if you are invoking any actions when the page is shown.

Brian__
Posts: 0
Joined: Tue Sep 03, 2013 11:33 am

Input Fields are being cleared when back button is pressed

Thanks, Max. Can you provide any explanation for the behaviour I mention in my initial post:

"when I press "Test" and launch the app, the input field is being populated with a value from a previous session. E.g. if I typed the string "blah" into the field in a previous session, when I make changes to the app, press "save", and press Test, the input component will have a value of "blah" even though I've started a new session. Is there any way of avoiding this?"

This is what I'm currently stuck on...

Brian__
Posts: 0
Joined: Tue Sep 03, 2013 11:33 am

Input Fields are being cleared when back button is pressed

To express the problem more concisely: "when testing in the browser, values of local storage variables are being preserved between sessions. Can this problem be avoided?"

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Input Fields are being cleared when back button is pressed

Local storage values are preserved between sessions and even if you close/open the browser. That's how local storage works

https://developer.mozilla.org/en-US/d...

Brian__
Posts: 0
Joined: Tue Sep 03, 2013 11:33 am

Input Fields are being cleared when back button is pressed

Ah... Apologies :-) That makes sense. But this should only occur during browser testing - correct? In an app in Android / IOS the variables should only persist as long as the app is open?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Input Fields are being cleared when back button is pressed

As you create a hybrid app in Appery.io (a mobile web app inside a native wrapper), local storage is still used the same way.

Return to “Issues”