我有一个带有用户名和密码TextFields的Angular2 2/Nativescript登录组件.当密码textField被编辑时,我将returnKeyType设置为" Done“,并期望在做完时,登录()函数会被按在软键盘上。此时,当按下键盘时,键盘就会被取消,但是登录函数不会被调用,所以在键盘被取消后,我仍然需要点击登录按钮才能提交表单。当返回键按在Nativescript中的特定TextField上时,是否有提交表单的方法?如果是这样的话,我如何着手实现它呢?我试过returnPress事件,但什么也没发生.
我的代码:
<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>发布于 2017-09-04 11:45:37
试试这个:
(returnPress)="login()"https://stackoverflow.com/questions/43200847
复制相似问题