tab.html 8.1 KB

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