阻止输入设备提交angularjs表单 [英] Prevent input device to submit angularjs form

查看:63
本文介绍了阻止输入设备提交angularjs表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中输入文本字段将由条形码中的扫描程序扫描填充。

I'm developing an application where an input text field will get populated by a scanner scanning in a barcode.

问题是当扫描程序扫描时,它提交表格。它无法在扫描仪上禁用,因此我需要在表单self上禁用它。我在考虑:

The problem is that when the scanner scans, it submits the form. It can't be disabled on the scanner, so I need to disable it on the form self. I was thinking about:

<form onsubmit="this.preventDefault()">

这是阻止自动提交的方式吗?

Is that the way to prevent the auto submission?

我的表单如下:

    <form name="form" novalidate>

                            <div class="form-group" ng-class="{'has-success': form.barcode.$valid, 'has-error': form.barcode.$invalid && form.barcode.$dirty}">
                                <label for="barcode" class="control-label">Barcode:</label>
                                <div class="input-group">
                                    <input type="text" ng-model="view.asset.barcode" name="barcode" ng-required="true" id="barcode" class="form-control" ng-change="validateBarcodeUnique(form)">
                                    <span class="input-group-addon"><i ng-class="{'icon-ok': form.barcode.$valid, 'icon-remove': form.barcode.$invalid && form.barcode.$dirty}"></i> </span>
                                </div>
                                <span class="help-block">
                                    <span ng-show="form.barcode.$error.required && form.barcode.$dirty">Barcode is required!</span>
                                    <span ng-show="form.barcode.$error.pattern && form.barcode.$dirty">Barcode is already used!</span>


                    </span>
                        </div>
...
                        <div>
                            <button ng-click="form.$setPristine(); updateAsset();" ng-disabled="form.$invalid || form.$pristine" type="submit" class="btn btn-success">Save</button>
                            <a ng-click="view.asset = null;" class="btn btn-danger">Cancel</a>
                            <div class="btn-group">
                                <a ng-show="assets.length > 1" ng-click="getPicSingle()" class="btn btn-primary">Take specific picture</a>
                                <a ng-show="view.asset.image_specific" ng-click="removePicSingle()" class="btn btn-danger"><i class="icon-trash"></i></a>
                            </div>
                        </div>
                    </form>

PS:如何修复粘贴代码的缩进?

PS: how do I fix the indenting of pasted code??

推荐答案

只需将按钮类型从提交更改为按钮即可阻止自动提交。

Just change button type from "submit" to "button" and it will prevent auto submission.

这篇关于阻止输入设备提交angularjs表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆