2014-11-06 81 views
4

我有一個窗體如下所示,爲簡單起見,我只保留1個字段。在我的形式中,我有許多其他領域,包括國家下拉菜單。如果選擇的國家是A,B或C,我希望刪除我使用addressRequired所需的驗證,該驗證在國家變化時獲得真/假值。添加刪除角度js動態角度需要驗證

我正在刪除所需的使用.removeAttr(),它確實從html中刪除。

ng-disabled="myAbcForm.$invalid"劇照顯示無效。

<form name="myAbcForm" ng-submit="submitForm(myAbcForm.$valid)" novalidate class="myAbcForm"> 
    <div class="element-box fltlt"> 
     <label>Address </label><sup ng-show="addressRequired">*</sup> 
     <input type="text" value="" ng-model="details.Address" required=""> 
     <span ng-show="!details.Address && addressRequired" class="error-msg field-validation-error">Address is required.</span> 
    </div> 
    <div id="clearfix"> 
     <input type="submit" value="Update" class="btn fltlt btnBG" ng-disabled="myAbcForm.$invalid" /> 
    </div> 
</form> 

有什麼建議嗎?

+0

現在用的什麼欲瞭解更多信息檢查這個: [http://stackoverflow.com/questions/16648669/what-is-the-difference-between-required-and-ng-required][1] [1]:HTTP:// stackoverflow.com/questions/16648669/what-is-the-difference-between-required-and-ng-required – Durgesh 2014-11-06 08:35:18

回答

3

使用ngRequired代替,如:

ng-required="checkCountry()" 

http://jsfiddle.net/coma/0jz49knd/1/

+0

checkCountry()函數應該返回什麼?一個布爾? – Yasser 2014-11-06 08:27:45

+1

@亞瑟,是的,我在小提琴上,但是,就像那樣。 – coma 2014-11-06 08:28:13

+0

感謝您從答案中獲得瞭解決方案。 – Yasser 2014-11-06 08:35:08

1

隨着一點點的暗示從coma'sanswer

這裏是我現在

<input type="text" value="" 
    ng-model="details.Address" 
    ng-required="addressRequired" />