我有一个字段,我想在表单提交时强制使用。
这是代码:
<div class="form-group">
<form name="addressform">
<span><small><strong> choose Location : </small></strong></span>
<div>
<input type="text" name="address" id="LocationAutocomplete" class="form-control" ng-autocomplete="result1" ng-model="addressTemp" required/>
</form>
<div ng-show="showMap">
<div id="location_map_canvas" style="width:100%;height:200px"> </div>
</div>
</div>
</div>
<div class="form-group">
<input type="submit" ng-submit value="create" ng-disabled="frm.$invalid" class="btn btn-primary btn-block" ng-click="createt()">
</div>
答案 0 :(得分:0)
<input name="movie" type="text" required />
这就是你需要输入文本字段的方法。
答案 1 :(得分:0)
<input type="text" id="LocationAutocomplete" class="form-control" ng-autocomplete="result1" ng-model="addressTemp" ng-required="required"/>
答案 2 :(得分:0)
使用ng-required="true"
,如下所示:
<input type="text" id="LocationAutocomplete" class="form-control" ng-autocomplete="result1" ng-model="addressTemp" ng-required="true" name="input"/>
<input type="submit" ng-disabled="myform.input.$error.required">Submit</input>
答案 3 :(得分:0)
使用angularjs表单验证 https://docs.angularjs.org/guide/forms - https://docs.angularjs.org/api/ng/type/form.FormController,其中包含ng-message和(https://docs.angularjs.org/api/ngMessages/directive/ngMessages)
如果你想提交(ng-submit =&#34; checkAndSave&#34;).. 在控制器中做..
graph {
"α" -- "β"
}
答案 4 :(得分:0)
添加表单标记,并为表单和所有输入命名
<form name="form" ng-submit="submitform()">
<input name="addres" type="text" id="LocationAutocomplete" class="form-control" ng-model="addressTemp" required/>
<button type="submit" ng-disabled="form.$invalid"> Submit </button>
</form>
这样,如果输入无效,您将禁用“提交”按钮。 因为它具有必需属性,如果输入为空,则显示为无效。
找到这个工作样本: https://plnkr.co/edit/F0Id7HDm9pkrCTTG42U5?p=preview
答案 5 :(得分:0)
试试这个有用的演示:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope) {
$scope.create = function() {
console.log("submitting..");
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<form name="addressform" ng-submit="addressform.$valid && create()" novalidate>
<span ng-show="submitted == true && addressform.address.$error.required">Required field.</span>
<div class="form-group">
<input type="text" name="address" id="LocationAutocomplete" class="form-control" ng-autocomplete="result1" ng-model="addressTemp" required/>
</div>
<div class="form-group">
<input type="submit" value="create" class="btn btn-primary btn-block" ng-click="submitted = true">
</div>
</form>
</div>
&#13;