表单部分的视图看起来像
<md-dialog aria-label="Add Attendee">
<form ng-cloak class="form-horizontal" name="attendeeForm" ng-submit="save(ctrl.attendee) && attendeeForm.$valid" novalidate>
<md-toolbar>
<div class="md-toolbar-tools">
<h2>Enter Attendee</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="cancel()">
<md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
<div class="md-dialog-content">
<div class="form-group">
<label for="firstName" class="control-label col-md-3 col-sm-4">First Name:</label>
<div class="col-sm-8"><input type="text" class="form-control" id="firstName" placeholder="First Name" name="firstName" ng-model="ctrl.attendee.firstName" ng-required="true" /></div>
</div>
<div class="form-group">
<label for="lastName" class="control-label col-md-3 col-sm-4">Last Name:</label>
<div class="col-sm-8"><input type="text" class="form-control" id="lastName" placeholder="Last Name" name="lastName" ng-model="ctrl.attendee.lastName" ng-required="true" /></div>
</div>
<div class="form-group">
<label for="email" class="control-label col-md-3 col-sm-4">Email:</label>
<div class="col-sm-8"><input type="email" class="form-control" id="email" placeholder="Email Address" name="email" ng-model="ctrl.attendee.email" ng-required="true" /></div>
</div>
</div>
</md-dialog-content>
<md-dialog-actions layout="row">
<span flex></span>
<button class="btn btn-primary" type="submit">Save Attendee</button>
</md-dialog-actions>
</form>
</md-dialog>
当我提交没有必填字段的表单时,表单会通过验证并可以提交。当我删除novalidate
时,根据来自Angularjs prevent form submission when input validation fails的回答没有任何意义,其中表示不需要控制器检查。
有什么想法吗?