首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angular2 2/Nativescript:在软键盘上按下返回键时提交一份表单

Angular2 2/Nativescript:在软键盘上按下返回键时提交一份表单
EN

Stack Overflow用户
提问于 2017-04-04 07:27:33
回答 1查看 1.2K关注 0票数 3

我有一个带有用户名和密码TextFields的Angular2 2/Nativescript登录组件.当密码textField被编辑时,我将returnKeyType设置为" Done“,并期望在做完时,登录()函数会被按在软键盘上。此时,当按下键盘时,键盘就会被取消,但是登录函数不会被调用,所以在键盘被取消后,我仍然需要点击登录按钮才能提交表单。当返回键按在Nativescript中的特定TextField上时,是否有提交表单的方法?如果是这样的话,我如何着手实现它呢?我试过returnPress事件,但什么也没发生.

我的代码:

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-04 11:45:37

试试这个:

代码语言:javascript
运行
复制
(returnPress)="login()"
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43200847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档