Search code examples
google-app-enginegoogle-apps-scriptgmail-addonsgoogle-apps-script-addon

Changing the value of event in CardService.newTextInput does not change the displayed value in textinput in gmail addon


I have simple gmail addon in which i am trying to make custom login form. The problem i am facing is that when i am changing the input field from on Change handler the displayed value is not changing . Trying to hide the password field.

Textinput widget

function getMembersSelectMenu(){

   var textInput = CardService.newTextInput()
    .setFieldName("Password")
    .setTitle("Password")
    .setHint("Enter Password")
    .setOnChangeAction(CardService.newAction()
    .setFunctionName("handlePasswordChange"))


return textInput;

}

handler function for textInput

function handlePasswordChange(e){
 // e.formInput.pass = e.formInput.Password;
  e.formInput.Password = "*";
  e.formInputs.Password = "******"
  Logger.log("my value object" + JSON.stringify(e));

}

Already checked the object and value is updated but not change in the view


Solution

  • When textInput field value is change, handlePasswordChange is called with eventObject. I think you're trying to set the value in that eventObject inside handlePasswordChange and not on that field.

    I think we can do something like this :

    1.Create some global variable to keep track of field.

    2.Create field and assign in that variable.

    3.On value change set value in that.

    var passwordField;
    
    function getMembersSelectMenu(){
         passwordField = CardService.newTextInput()
            .setFieldName("Password")
            .setTitle("Password")
            .setHint("Enter Password")
            .setOnChangeAction(CardService.newAction()
            .setFunctionName("handlePasswordChange"))
        return passwordField;
    }
    
    function handlePasswordChange(e){
        // e.formInput.pass = e.formInput.Password;
        passwordField.setValue("*******");
    }