Question

Below is the code i use for my cloud user login...the slight problem is; whenever i login and logout, data inserted into the textfields does not disappear...i don't want them to be saved, i want users to insert textfields all over again after logout.

//create textfields for sign_in page/interface
var userNameField = Titanium.UI.createTextField({
color: 'black',
hintText: 'username',
height: 35,
top: 120,
left: 10,
width: 250,
borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(userNameField);





var passwordField = Titanium.UI.createTextField({
color: 'black',
hintText: 'password',
height: 35,
top: 160,
left: 10,
width: 250,
passwordMask: true,
borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(passwordField);





var button = Titanium.UI.createButton({
title: 'log in',
top: 190,
left: 10,
width: 100,
height:50,
Color:'#336699'
});
win.add(button);



//then create event listener and login user to ACS cloud server
button.addEventListener('click', function(){
Cloud.Users.login({
    login: userNameField.value,
    password: passwordField.value,
}, function (e) {
    if (e.success) {
        var user = e.users[0];
alert('success');
    } else {
        alert('Unable to log you in:' + e.message);
    }
    });
});
Was it helpful?

Solution

I think you want to clear the textfields. You just need to empty the textFields upon successful login. For this you just need to modify your code as follows

button.addEventListener('click', function(){
    Cloud.Users.login({
        login: userNameField.value,
        password: passwordField.value
    }, function (e) {
        if (e.success) {
            var user = e.users[0];
            //Clears the TiUITextField's values
            userNameField.value = ""; 
            passwordField.value = "";
            alert('success');
        } else {
            alert('Unable to log you in:' + e.message);
        }
    });
});

This will do the trick :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top