smartwizard-input.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Smart Wizard - a JavaScript jQuery Step Wizard plugin</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <!-- Include Bootstrap CSS -->
  8. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  9. <!-- Optional Bootstrap Theme -->
  10. <link rel="stylesheet" href="../dist/css/bootstrap.min.css">
  11. <!-- Include SmartWizard CSS -->
  12. <link href="../dist/css/smart_wizard.css" rel="stylesheet" type="text/css" />
  13. <!-- Optional SmartWizard theme -->
  14. <link href="../dist/css/smart_wizard_theme_dots.css" rel="stylesheet" type="text/css" />
  15. </head>
  16. <body>
  17. <div class="container">
  18. <br />
  19. <form action="#" id="myForm" role="form" data-toggle="validator" method="post" accept-charset="utf-8">
  20. <!-- SmartWizard html -->
  21. <div id="smartwizard">
  22. <ul>
  23. <li><a href="#step-1">Step 1<br /><small>Email Address</small></a></li>
  24. <li><a href="#step-2">Step 2<br /><small>Name</small></a></li>
  25. <li><a href="#step-3">Step 3<br /><small>Address</small></a></li>
  26. <li><a href="#step-4">Step 4<br /><small>Terms and Conditions</small></a></li>
  27. </ul>
  28. <div>
  29. <div id="step-1">
  30. <h2>Your Email Address</h2>
  31. <div id="form-step-0" role="form" data-toggle="validator">
  32. <div class="form-group">
  33. <label for="email">Email address:</label>
  34. <input pattern="^[0-9]{1,}$" class="form-control" name="email" id="email" placeholder="Write your email address" required>
  35. <div class="help-block with-errors"></div>
  36. </div>
  37. </div>
  38. </div>
  39. <div id="step-2">
  40. <h2>Your Name</h2>
  41. <div id="form-step-1" role="form" data-toggle="validator">
  42. <div class="form-group">
  43. <label for="name">Name:</label>
  44. <input type="text" class="form-control" name="name" id="email" placeholder="Write your name" required>
  45. <div class="help-block with-errors"></div>
  46. </div>
  47. </div>
  48. </div>
  49. <div id="step-3">
  50. <h2>Your Address</h2>
  51. <div id="form-step-2" role="form" data-toggle="validator">
  52. <div class="form-group">
  53. <label for="address">Address</label>
  54. <textarea class="form-control" name="address" id="address" rows="3" placeholder="Write your address..." required></textarea>
  55. <div class="help-block with-errors"></div>
  56. </div>
  57. </div>
  58. </div>
  59. <div id="step-4" class="">
  60. <h2>Terms and Conditions</h2>
  61. <p>
  62. Terms and conditions: Keep your smile :)
  63. </p>
  64. <div id="form-step-3" role="form" data-toggle="validator">
  65. <div class="form-group">
  66. <label for="terms">I agree with the T&C</label>
  67. <input type="checkbox" id="terms" data-error="Please accept the Terms and Conditions" required>
  68. <div class="help-block with-errors"></div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. <div class=""><button id="next-step">下一步</button></div>
  75. </form>
  76. </div>
  77. <!-- Include jQuery -->
  78. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  79. <!-- Include jQuery Validator plugin -->
  80. <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"></script>
  81. <!-- Include SmartWizard JavaScript source -->
  82. <script type="text/javascript" src="../dist/js/jquery.smartWizard.min.js"></script>
  83. <script type="text/javascript">
  84. $(document).ready(function(){
  85. // Toolbar extra buttons
  86. var btnFinish = $('<button></button>').text('Finish')
  87. .addClass('btn btn-info')
  88. .on('click', function(){
  89. if( !$(this).hasClass('disabled')){
  90. var elmForm = $("#myForm");
  91. if(elmForm){
  92. elmForm.validator('validate');
  93. var elmErr = elmForm.find('.has-error');
  94. if(elmErr && elmErr.length > 0){
  95. alert('Oops we still have error in the form');
  96. return false;
  97. }else{
  98. alert('Great! we are ready to submit form');
  99. elmForm.submit();
  100. return false;
  101. }
  102. }
  103. }
  104. });
  105. var btnCancel = $('<button></button>').text('Cancel')
  106. .addClass('btn btn-danger')
  107. .on('click', function(){
  108. $('#smartwizard').smartWizard("reset");
  109. $('#myForm').find("input, textarea").val("");
  110. });
  111. // Smart Wizard
  112. var smartWizard = $('#smartwizard').smartWizard({
  113. selected: 0,
  114. theme: 'dots',
  115. transitionEffect:'fade',
  116. useURLhash: false,
  117. toolbarSettings: {toolbarPosition: 'bottom',
  118. // toolbarExtraButtons: [btnFinish, btnCancel]
  119. showNextButton: false, // show/hide a Next button
  120. showPreviousButton: false, // show/hide a Previous button
  121. },
  122. anchorSettings: {
  123. markDoneStep: true, // add done css
  124. markAllPreviousStepsAsDone: true, // When a step selected by url hash, all previous steps are marked done
  125. removeDoneStepOnNavigateBack: true, // While navigate back done step after active step will be cleared
  126. enableAnchorOnDoneStep: true // Enable/Disable the done steps navigation
  127. }
  128. });
  129. smartWizard = smartWizard.data('smartWizard');
  130. $("#smartwizard").on("leaveStep", function(e, anchorObject, stepNumber, stepDirection) {
  131. var elmForm = $("#form-step-" + stepNumber);
  132. // stepDirection === 'forward' :- this condition allows to do the form validation
  133. // only on forward navigation, that makes easy navigation on backwards still do the validation when going next
  134. console.log('leaveStep', anchorObject, stepNumber, stepDirection, elmForm);
  135. if(stepDirection === 'forward' && elmForm){
  136. elmForm.validator('validate');
  137. var elmErr = elmForm.children('.has-error');
  138. if(elmErr && elmErr.length > 0){
  139. // Form validation failed
  140. return false;
  141. }
  142. }
  143. return true;
  144. });
  145. $("#smartwizard").on("showStep", function(e, anchorObject, stepNumber, stepDirection) {
  146. // Enable finish button only on last step
  147. if(stepNumber == 3){
  148. $('.btn-finish').removeClass('disabled');
  149. }else{
  150. $('.btn-finish').addClass('disabled');
  151. }
  152. });
  153. var $sw = $("#smartwizard");
  154. $('#next-step').click(function (e) {
  155. console.log(smartWizard.current_index, '点击下一步按钮');
  156. e.preventDefault();
  157. if (smartWizard.steps.index(this) !== smartWizard.current_index) {
  158. smartWizard.next();
  159. }
  160. });
  161. });
  162. </script>
  163. </body>
  164. </html>