<form name="companyProfileForm" autocomplete="false" novalidate ng-submit="OnSaveCompanyProfile(companyProfileForm.$valid)" ng-controller="companyProfileDataEntryController">
<section ng-hide="!IsCompanyKnown();" class="row">
<div class="small-12 medium-6 large-6 columns">
<!--Industry-->
<section class="row">
<div class="small-12 medium-12 large-12 columns" ng-class="{ 'has-error' : (companyProfileForm.Industry.$invalid && submitted) }">
<div class="form-group">
<label for="Industry">*Industry</label>
<select name="Industry"
ng-model="CompanyProfileModel.IndustryId"
ng-options="item.Id as item.Description for item in IndustryList"
required>
<option value=null>-- select an industry --</option>
</select>
<span class="help-block" ng-show="companyProfileForm.Industry.$invalid && submitted">Please select a value.</span>
</div>
</div>
</section>
</div>
</section>
<button></button>
</form>
无论我做什么,这个表格都会评估为真。我希望它抛出一个需要Industry的错误。提交后,它将转到一个函数,该参数将打印到控制台。每次打印都是真的。
答案 0 :(得分:0)
您需要使用AngularJS ng-required指令,而不是必需的。更改ng-required =“true”所需的select元素:
<select name="Industry" ng-model="CompanyProfileModel.IndustryId" ng-options="item.Id as item.Description for item in IndustryList" ng-required="true">
<option value=null>-- select an industry --</option>
</select>
答案 1 :(得分:0)
使用&#39; required&#39;只要您的表单元素具有ng-submit =&#34; action()&#34;表单元素将以角度工作以及表格中的一个按钮如下:
<button type='submit' ng-click='submit()'>SomeText</button>