2017-04-04 50 views
0

我有一個帶有用戶名和密碼的Angular2/Nativescript登錄組件TextFields ...當編輯密碼textField時,我將returnKeyType設置爲「done」,並且期望在軟鍵盤上按下完成時調用login()函數。在按下完成鍵時,鍵盤被解除了,但登錄功能沒有被調用,所以在鍵盤被解除之後,我仍然需要點擊登錄按鈕來提交表單。在Nativescript中的特定TextField上按下返回鍵時,是否有任何方式提交表單?如果是的話我該如何去實施它?我試過returnPress事件,但沒有任何反應......Angular2/Nativescript:在軟鍵盤上按下返回鍵時提交表單

我的代碼:

<ActionBar title="Login"></ActionBar> 
<StackLayout class="page"> 
    <GridLayout columns="*, auto" rows="auto"> 
     <ActivityIndicator class="m-l-10 m-t-10 activity-indicator" [busy]="busy" [visibility]="busy ? 'visible' : 'collapse'" horizontalAlignment="left"></ActivityIndicator> 
     <Button row="0" col="1" id="setIPBtn" class=" m-t-20 pull-right font-awesome" text="&#xf0ad; Settings" (tap)="setIP()"></Button> 
    </GridLayout> 

    <Label class="m-x-auto m-t-20 title h1 text-primary p-x-10" text="Log In" backgroundColor="blue"></Label> 
    <StackLayout class="form"> 
     <StackLayout class="input-field"> 
      <Label class="body label text-left" text="Enter Username"></Label> 
      <TextField class="input input-border" hint="Username" [(ngModel)]="username" autocorrect="false" autocapitalizationType="none" returnKeyType="next"></TextField> 
     </StackLayout> 
     <StackLayout class="input-field"> 
      <Label class="body label text-left" text="Enter Username"></Label> 
      <TextField class="input input-border" secure="true" hint="Password" [(ngModel)]="password" autocorrect="false" autocapitalizationType="none" returnKeyType="done" returnPress="login()"></TextField>    
     </StackLayout> 
     <Button class="btn btn-submit font-awesome bg-primary" [text]="isLoggingIn ? 'Logging in...' : '&#xf090; Login'" (tap)="login()" [isEnabled]="username !== '' && username !== null && password !== '' && password !== null && !isLoggingIn"></Button> 
    </StackLayout>  



</StackLayout> 

回答

1

試試這個:

(returnPress)="login()" 
相關問題