tab.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>BootstrapValidator demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css" />
  8. <script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
  9. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  10. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <div class="row">
  15. <section>
  16. <div class="col-lg-8 col-lg-offset-2">
  17. <div class="page-header">
  18. <h2>Tab example</h2>
  19. </div>
  20. <ul class="nav nav-tabs">
  21. <li class="active"><a href="#info-tab" data-toggle="tab">Information <i class="fa"></i></a></li>
  22. <li><a href="#address-tab" data-toggle="tab">Address <i class="fa"></i></a></li>
  23. </ul>
  24. <form id="accountForm" method="post" class="form-horizontal" action="target.php" style="margin-top: 20px;">
  25. <div class="tab-content">
  26. <div class="tab-pane active" id="info-tab">
  27. <div class="form-group">
  28. <label class="col-lg-3 control-label">Full name</label>
  29. <div class="col-lg-5">
  30. <input type="text" class="form-control" name="fullName" />
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-lg-3 control-label">Company</label>
  35. <div class="col-lg-5">
  36. <input type="text" class="form-control" name="company" />
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-lg-3 control-label">Job title</label>
  41. <div class="col-lg-5">
  42. <input type="text" class="form-control" name="jobTitle" />
  43. </div>
  44. </div>
  45. </div>
  46. <div class="tab-pane" id="address-tab">
  47. <div class="form-group">
  48. <label class="col-lg-3 control-label">Address</label>
  49. <div class="col-lg-5">
  50. <input type="text" class="form-control" name="address" />
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <label class="col-lg-3 control-label">City</label>
  55. <div class="col-lg-5">
  56. <input type="text" class="form-control" name="city" />
  57. </div>
  58. </div>
  59. <div class="form-group">
  60. <label class="col-lg-3 control-label">Country</label>
  61. <div class="col-lg-5">
  62. <select class="form-control" name="country">
  63. <option value="">Select a country</option>
  64. <option value="FR">France</option>
  65. <option value="DE">Germany</option>
  66. <option value="IT">Italy</option>
  67. <option value="JP">Japan</option>
  68. <option value="RU">Russian</option>
  69. <option value="US">United State</option>
  70. <option value="GB">United Kingdom</option>
  71. <option value="other">Other</option>
  72. </select>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. <div class="form-group">
  78. <div class="col-lg-5 col-lg-offset-3">
  79. <button type="submit" class="btn btn-primary">Validate</button>
  80. </div>
  81. </div>
  82. </form>
  83. </div>
  84. </section>
  85. </div>
  86. </div>
  87. <script type="text/javascript">
  88. $(document).ready(function() {
  89. $('#accountForm')
  90. .bootstrapValidator({
  91. excluded: [':disabled'],
  92. feedbackIcons: {
  93. valid: 'glyphicon glyphicon-ok',
  94. invalid: 'glyphicon glyphicon-remove',
  95. validating: 'glyphicon glyphicon-refresh'
  96. },
  97. fields: {
  98. fullName: {
  99. validators: {
  100. notEmpty: {
  101. message: 'The full name is required'
  102. }
  103. }
  104. },
  105. company: {
  106. validators: {
  107. notEmpty: {
  108. message: 'The company name is required'
  109. }
  110. }
  111. },
  112. jobTitle: {
  113. validators: {
  114. notEmpty: {
  115. message: 'The company name is required'
  116. }
  117. }
  118. },
  119. address: {
  120. validators: {
  121. notEmpty: {
  122. message: 'The address is required'
  123. }
  124. }
  125. },
  126. city: {
  127. validators: {
  128. notEmpty: {
  129. message: 'The city is required'
  130. }
  131. }
  132. },
  133. country: {
  134. validators: {
  135. notEmpty: {
  136. message: 'The city is required'
  137. }
  138. }
  139. }
  140. }
  141. })
  142. .on('status.field.bv', function(e, data) {
  143. var $form = $(e.target),
  144. validator = data.bv,
  145. $tabPane = data.element.parents('.tab-pane'),
  146. tabId = $tabPane.attr('id');
  147. if (tabId) {
  148. var $icon = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent().find('i');
  149. // Add custom class to tab containing the field
  150. if (data.status == validator.STATUS_INVALID) {
  151. $icon.removeClass('fa-check').addClass('fa-times');
  152. } else if (data.status == validator.STATUS_VALID) {
  153. var isValidTab = validator.isValidContainer($tabPane);
  154. $icon.removeClass('fa-check fa-times')
  155. .addClass(isValidTab ? 'fa-check' : 'fa-times');
  156. }
  157. }
  158. });
  159. });
  160. </script>
  161. </body>
  162. </html>