Home > Blockchain >  Navigate to card without Button action
Navigate to card without Button action

Time:05-01

I try to make a login screen so add card for login [username & password & button(Action)] this action works fine and execute the code correctly but at end i want to leave the card to another one, based on Google document i have to add action to navigate, but i don't know how to navigate from the code.

Login Card :

function LoginCard() {
    let cardSection1TextInput1 = CardService.newTextInput()
        .setFieldName('username')
        .setTitle('Email')
        .setMultiline(false);

    let cardSection1TextInput2 = CardService.newTextInput()
        .setFieldName('password')
        .setTitle('Password')
        .setMultiline(true);

    let cardSection1ButtonList1Button1Action1 = CardService.newAction()
       .setFunctionName('handleLogin') // <-- This Works Fine

    let cardSection1ButtonList1Button1 = CardService.newTextButton()
        .setText('Login')
        .setBackgroundColor('#1cdcf4')
        .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
        .setOnClickAction(cardSection1ButtonList1Button1Action1);

    let cardSection1ButtonList1 = CardService.newButtonSet()
        .addButton(cardSection1ButtonList1Button1);

    let cardSection1 = CardService.newCardSection()
        .addWidget(cardSection1Image1)
        .addWidget(cardSection1TextInput1)
        .addWidget(cardSection1TextInput2)
        .addWidget(cardSection1ButtonList1);


    let card = CardService.newCardBuilder()
        .addSection(cardSection1);
    return card.build();
}

Login handle function :

function handleLogin(e) {
    try {       
          let nav = CardService.newNavigation().pushCard(Dashboard());
            CardService.newActionResponseBuilder()
            .setNavigation(nav)
            .build();
          // This not navigate to anyway!!
    }catch(e){
    Logger.log(e);
    }
}

searching but no cleat answer and no exception at that line

CodePudding user response:

to show card you have to make the function return the new card, try the below code :

function handleLogin(e) {
    try {       
          let nav = CardService.newNavigation().pushCard(Dashboard());
            return CardService.newActionResponseBuilder()
            .setNavigation(nav)
            .build();

    }catch(e){
    Logger.log(e);
    }
}
  • Related