0

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);
    }
    });
});
4

1 回答 1

1

我想你想清除文本字段。您只需要在成功登录后清空文本字段。为此,您只需要按如下方式修改您的代码

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);
        }
    });
});

这会成功的:)

于 2013-10-10T18:50:24.680 回答