2014-10-27 91 views
0
<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> 

不管我做什麼,這個表格都會評估爲真。我希望它拋出一個錯誤,即行業是必需的。提交後,它將轉到一個可以在控制檯上輸出參數的功能。它每次都打印真實。爲什麼這種形式評估爲真?

回答

0

您需要使用AngularJS ng-required指令,不需要。切換到所需的選擇元素NG-所需=「真」:

<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> 
0

一個表單元素上使用「必要」 將在角工作,只要你形式元素有一個NG提交=」動作()「和一個按鈕,內容如下:

<button type='submit' ng-click='submit()'>SomeText</button> 
相關問題