2016-03-15 138 views
2

我在表單上有幾個md-select下拉列表,其中很多都有驗證。驗證正常工作在所有的下拉菜單,除了以下,這並不妨礙形式從提交如果空:角質材料md-select驗證問題

<md-input-container class="form-input-container" 
         flex="15"> 
     <label>NDRA*</label> 
     <md-select id="registration-information-ndra" 
       name="ndra" 
       ng-model="vm.registration.code" 
       ng-class="{'validation-error': newForm.ndra.$error.required && newForm.$submitted}" 
       ng-required="vm.validation.ndra"> 
     <md-option ng-repeat="code in vm.dropdowns.codes" 
        value="{{code}}"> 
      {{code}} 
     </md-option> 
     </md-select> 
    </md-input-container> 

vm.validation.ndra計算結果爲真實的,所以我知道這不是問題。如果我看VS工作選擇選項newForm.ndra的值,如newForm.submissionDate,我得到如下:

newForm.ndra: {"$viewValue":"p","$modelValue":"p","$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":true,"$dirty":false,"$valid":true,"$invalid":false,"$error":{},"$name":"ndra","$options":null}

註冊類型(驗證工作):

<md-input-container class="form-input-container padded-input md-block" 
          flex-gt-sm=""> 
      <label>Type of Registration*</label> 
      <md-select id="registration-information-type" 
        name="registrationType" 
        ng-model="vm.registration.type" 
        ng-class="{'validation-error': newForm.registrationType.$error.required && newForm.$submitted}" 
        ng-required="vm.validation.registrationType"> 
      <md-option ng-repeat="type in vm.dropdowns.types" 
         value="{{type}}"> 
       {{type}} 
      </md-option> 
      </md-select> 
     </md-input-container> 

{"$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":true,"$dirty":false,"$valid":false,"$invalid":true,"$error":{"required":true},"$name":"registrationType","$options":null}

+0

您能否提供有關此問題的更多信息?你有缺省選擇還是空的選擇? – Malachi

+0

您是否也可以顯示您列出的其他選項的標記? – Malachi

+1

剛剛加了標記 –

回答

2

想通了。在我的控制器代碼深處,控制器正在被實例化,然後this.registration.code被設置爲P,所以ndra下拉列表的模型已經有了一個值。

1

我在想你的vm.validation.ndra正在返回與你的vm.validation.registrationType返回的相反。所以選擇不是必需的。如果你看一下返回什麼

...

國家藥品管理機構

"$valid":true,"$invalid":false 

註冊類型

"$valid":false,"$invalid":true 

它們完全相反。

,你應該檢查,以確保您得到正確的truthy在vm.validation.ndra

+0

這沒有奏效。我在原始文章中添加了更多關於表單輸入值的信息。 –

+1

改變了我的回答 – Malachi

+0

我檢查了'vm.validation.ndra'和'vm.validation.registrationType' - 它們都返回true。 –