【问题标题】:Is there any way to allow users to select a blank value from angular dropdown menu有没有办法让用户从角度下拉菜单中选择一个空白值
【发布时间】:2014-09-24 03:25:35
【问题描述】:

我有一个带有保存按钮的表单,该按钮正在使用 $pristine$invalid 属性禁用。表单有一个下拉菜单,其中包含一个空白值作为选择选项。一旦我选择了空白值,它总是将 from 的 $invalid 属性设置为 false。谁能建议我一个选择?

我的保存按钮代码是这样的

<button class="btn btn-primary app-form-buttons" disabled="disabled" name="btnSave" ng-     disabled="myForm.$pristine || myForm.$invalid" type="submit">
    <i class="icon-save"></i>
</button>

这样下拉代码

<div class="col-sm-8 col-xs-11">
  <select class="form-control" name="Type" ng-model="bus.route" required ng-options="bus.type as type.Type for type in types" >
    <option>---Please Choose---</option>
  </select>
</div>

【问题讨论】:

    标签: javascript angularjs ng-options


    【解决方案1】:

    您似乎需要将占位符选项设置为禁用,因为您不希望它被选中。

    <div class="col-sm-8 col-xs-11">
       <select class="form-control" name="Type" ng-model="bus.route" ng-options="bus.type as type.Type for type in types" >
           <option disabled>---Please Choose---</option>
       </select>
    </div>
    

    【讨论】:

    • 问题仍然存在,因为 select 具有必需的属性
    【解决方案2】:

    问题已解决。我试图使用 required 属性验证表单。当我选择空白值时,这给了我一个无效的错误。为了克服这个问题,我在 disable 属性中使用了自定义方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多