我正在尝试根据条件设置必填字段。这是我的代码。
<div id= 'outer-form' ng-form='main' validate-on-submit='#page-errors' on-invalid='DisplayErrors();' on-valid="SubmitPage();'>
...other div's
<div ng-repeat='myItem in aFunction.myItemArray' ng-form='sub'>
<div ng-show= 'myType == "Shoes"'>
@Html.TextBox('Shoes', null, new { ng_model = 'Shoes', ng_required = 'myType == "Shoes"' })
<span ng-show="sub.Shoes.$error.Text">Shoes required</span>
</div>
<div ng-show= 'myType == "Socks"'>
@Html.TextBox('Socks', null, new { ng_model = 'Socks', ng_required = 'myType == "Socks"' })
<span ng-show="sub.Socks.$error.Text">Socks required</span>
</div>
<button class="clientContinue" id="step-submit-btn">CONTINUE</button>
</div>
我发现this对我不起作用。我被困住所以任何帮助/建议将不胜感激。谢谢!
答案 0 :(得分:0)
我不知道您在示例中使用了哪种模板引擎,但是如果它支持根据布尔值添加属性,则代码看起来正确。
说到Angular,看起来你需要一个自定义验证器(类型验证器),你可以将类型作为HTML属性传递。在验证器内部,您将能够非常轻松地控制所需的标志。
您可以在以下链接中找到有关自定义验证程序的更多信息:http://docs.angularjs.org/guide/forms