forms
  • validation
  • angularjs
  • 2014-01-08 23 views 0 likes 
    0

    我想根据条件设置必填字段。这是我的代码。如何获取所需的信息以在AngularJs中切换?

    <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这对我不起作用。我卡住,所以任何帮助/建议将不胜感激。谢谢!!

    +1

    这是什么模板引擎?你可以在纯HTML中显示代码吗? –

    回答

    0

    我不知道你在你的例子中使用了什么样的模板引擎,但是如果它支持根据布尔值添加属性,你的代码看起来是正确的。

    说到Angular,看起来您需要一个自定义验证器(类型验证器),您可以在其中将该类型作为HTML属性传递。在验证器内部,您可以非常轻松地控制所需的标志。

    你可以找到关于下面的链接自定义验证的详细信息:http://docs.angularjs.org/guide/forms

    相关问题