Angular2/Nativescript:在软键盘上按下返回键时提交表单
问题描述:
我有一个带有用户名和密码的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=" 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...' : ' Login'" (tap)="login()" [isEnabled]="username !== '' && username !== null && password !== '' && password !== null && !isLoggingIn"></Button>
</StackLayout>
</StackLayout>
答
试试这个:
(returnPress)="login()"