【问题标题】:Angular2/Nativescript: Submit a form when return key is pressed on soft keyboardAngular2 / Nativescript:在软键盘上按下返回键时提交表单
【发布时间】:2017-04-04 07:27:33
【问题描述】:

我有一个带有用户名和密码 TextFields 的 Angular2/Nativescript 登录组件...在编辑密码 textField 时,我将 returnKeyType 设置为“done”,并期望在按下 Done 时调用 login() 函数软键盘。在按下完成的那一刻,键盘被关闭但登录功能没有被调用,所以我仍然必须在键盘被关闭后点击登录按钮才能提交表单。当在 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="&#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>

【问题讨论】:

    标签: angular nativescript angular2-nativescript


    【解决方案1】:

    试试这个:

    (returnPress)="login()"
    

    【讨论】:

    • 此外,将returnKeyType="done" 添加到输入组件也很重要,这样用户就知道它将像问题中的示例一样发送表单。
    猜你喜欢
    • 2014-12-26
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多