2014-01-25 76 views
3

我的第一篇文章在stackoverflow,所以要温柔。我是一个新手学习者:) 即时通讯使用Twitter Bootstrap 3建立表格。 在这种形式下,我有一个允许用户选择国家的下拉菜单。 我的问题是:我如何使这个“必需”字段? 我不想要表单被提交,如果该字段被跳过。 即时通讯使用“必需”字段像这样,它适用于基本文本类型。Bootstrap 3 - 表单 - 必填字段 - Drop Down

<input type="text" class="form-control" placeholder="Enter Name..." required /> 

但我不知道我在哪里插入“必需”,当使用下拉菜单。 我试图用任何额外的jquery/js来做到这一点。 已经包括jQuery的1.10.2.js和bootstrap.js

bootply.com snippet

请帮助。

回答

5

必需属性可以添加到select元素。从你的例子:

<div class="form-group"> 
      <label for="country" class="col-sm-3 control-label">Country *</label> 
      <div class="col-sm-6"> 
      <select id="country" name="country" class="form-control" required> 

我还添加了id和name属性到你的select元素以保证完整性。

+0

谢谢,这有帮助。 – TheAllSeeingI

+0

同样重要的是要注意,如果没有选择项目,第一个

0
===.js=== 
$scope.addNewGuide = function(isValid) { 

    if (_.isEmpty($scope.selectedCategory)) { 
     isValid = false; 
     $scope.notSelectedCategory = true; 
    } 
} 
=====.html==== 
<form name="guide" ng-submit="addNewGuide(GuideListing.$valid)" novalidate> 
    <div class="col-md-4"> 
    <div class="scrolldiv"> 
     <ul class="none ulstyle"> 
     <li ng-repeat="categories in getCategoryAPIData" ng-if='categories.category.name.length>0'> 
      <label> 
      <input type="checkbox" id="chkCategory" name="chkCategory" ng-model="categories.category.chkCategory" ng-change="selectCategory(categories,categories.category.chkCategory)">{{categories.category.name}} 
      </label> 
     </li> 
     </ul> 
    </div> 
    <span class="help-block redtext" ng-show="`notSelectedCategory`">Please select Category</span> 
    </div> 
</div> 

<input type="submit"> 
</form>