Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

clear textinput on screenload

Hi,
I have 2 textinputs "Time and Date"
which are set from mobiscroll on screenload,

this is ok but when user finishes and navigate to another sreen or close the app, the next time they return to the screen the inputs load from localstorage.

I need to clear these inputs when the user is arriving to this screen from any page within the app except the mobiscroll screen,

I hope I explained it correctly

thanks

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

clear textinput on screenload

You could add some logic, on page load to clear set the fields to empty string, instead of reading the values from local storage.

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

clear textinput on screenload

Hello! You can check previous page name on Page Show event using the following JS:

codevar prevPageName = '';
if(arguments[1]["prevPage"][0]) {
prevPageName = $(arguments[1]["prevPage"][0]).attr("dsid");
}
if (prevPageName == 'mobiscroll') {
.............
}/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

clear textinput on screenload

Hi Marina,
I have tried this code but not working, is this what you meant or have I inserted the wrong code

codevar prevPageName = '';
if(arguments[1]["prevPage"][0]) {
prevPageName = $(arguments[1]["prevPage"][0]).attr("dsid");
}
if (prevPageName == 'mobiscroll') {
Tiggzi("timeinput").val(localStorage.getItem("selectedTime"));
Tiggzi("dateinput").val(localStorage.getItem("selectedDate"));
}code/code/code

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

clear textinput on screenload

The code looks correct. Please ensure you put this code on Page Show event and your screen calls mobilescroll (the record is case sensitive).

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

clear textinput on screenload

You can also add codealert(prevPageName);/code before code if (prevPageName == 'mobiscroll')/code to see what you get

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

clear textinput on screenload

Sorry, your screen name in editor should be mobiscroll

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

clear textinput on screenload

Hi,
I need to check if I have placed js on wrong screen.

on the mobiscroll screen the time and date are set, app navs to book screen where time and date inputs are,

on book screen I have added the code above on page show
the result is date and time inputs are empty now empty from every screen,

have I missed something, no errors on console

thanks for the help

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

clear textinput on screenload

Hi, please replace codeif (prevPageName == 'mobiscroll')/code
with the following codeif (prevPageName == 'Mobiscroll')/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

clear textinput on screenload

Cheers Marina,
all works from all pages, it works in browser as a visual,

but for some reason the code below which is the code used to set the date and time on Mobiscroll screen is not updating the variable on first click, works on second.

So in the browser the time and date are correct in the inputs,
but the previous selected time and date is the one send in the email, and so on,
sends the previous selected

codevar Date1 = Tiggr('Date1Val');
var selectedDate = Date1.scroller('getDate');
var m = (selectedDate.getMonth()+1 9) ? "" + (selectedDate.getMonth()+1) : "0" + (selectedDate.getMonth()+1),
d = (selectedDate.getDate() 9) ? "" + (selectedDate.getDate()) : "0" + (selectedDate.getDate()),
y = selectedDate.getFullYear();
var dateString = d + "/" + m + "/" + y;
localStorage.setItem('selectedDate', dateString);

var Time1 = Tiggr('Time1Val');
var selectedTime = Time1.scroller('getDate');
var h = (selectedTime.getHours() 9) ? "" + selectedTime.getHours() : "0" + selectedTime.getHours(),
m = (selectedTime.getMinutes() 9) ? "" + selectedTime.getMinutes() : "0" + selectedTime.getMinutes(),
s = (selectedTime.getSeconds() 9) ? "" + selectedTime.getSeconds() : "0" + selectedTime.getSeconds();
var timeString = h + ":" + m + ":" + s;
localStorage.setItem('selectedTime', timeString);code

Tiggzi.navigateTo('Book', {})

/code/code

Return to “Issues”