【问题标题】:Invalidate form if disabled select option is chosen如果选择禁用选择选项,则使表单无效
【发布时间】:2016-07-21 16:48:08
【问题描述】:

如果在我的选择标签中选择了value="0",是否有办法使表单无效?我这样做的原因是在用户看到任何内容之前显示默认选择选项。

但是即使用户没有选择任何东西,表单也是有效的。

<form name="add_task_frm" ng-submit="!add_task_frm.$valid || functiontoUse()" novalidate>

    <input type="text" ng-model="name" required />

    <select ng-model="action" required>
        <option value="0" selected disabled>Choose an Action</option>
        <option value="description">See Description</option>
        <option value="view">View</option>
    </select>

    <button type="submit">Submit</button>

</form>

【问题讨论】:

    标签: html angularjs angularjs-validation


    【解决方案1】:

    我认为您可以从第一个选项中删除该值,如果用户没有选择任何内容,这应该会使其无效。但是,我建议更改此实现以使用 ng-options。

    https://docs.angularjs.org/api/ng/directive/ngOptions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-13
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      相关资源
      最近更新 更多