form-wizard.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. $(function () {
  2. //Horizontal form basic
  3. $('#wizard_horizontal').steps({
  4. headerTag: 'h2',
  5. bodyTag: 'section',
  6. transitionEffect: 'slideLeft',
  7. onInit: function (event, currentIndex) {
  8. setButtonWavesEffect(event);
  9. },
  10. onStepChanged: function (event, currentIndex, priorIndex) {
  11. setButtonWavesEffect(event);
  12. }
  13. });
  14. //Vertical form basic
  15. $('#wizard_vertical').steps({
  16. headerTag: 'h2',
  17. bodyTag: 'section',
  18. transitionEffect: 'slideLeft',
  19. stepsOrientation: 'vertical',
  20. onInit: function (event, currentIndex) {
  21. setButtonWavesEffect(event);
  22. },
  23. onStepChanged: function (event, currentIndex, priorIndex) {
  24. setButtonWavesEffect(event);
  25. }
  26. });
  27. //Advanced form with validation
  28. var form = $('#wizard_with_validation').show();
  29. form.steps({
  30. headerTag: 'h3',
  31. bodyTag: 'fieldset',
  32. transitionEffect: 'slideLeft',
  33. onInit: function (event, currentIndex) {
  34. $.AdminBSB.input.activate();
  35. //Set tab width
  36. var $tab = $(event.currentTarget).find('ul[role="tablist"] li');
  37. var tabCount = $tab.length;
  38. $tab.css('width', (100 / tabCount) + '%');
  39. //set button waves effect
  40. setButtonWavesEffect(event);
  41. },
  42. onStepChanging: function (event, currentIndex, newIndex) {
  43. if (currentIndex > newIndex) { return true; }
  44. if (currentIndex < newIndex) {
  45. form.find('.body:eq(' + newIndex + ') label.error').remove();
  46. form.find('.body:eq(' + newIndex + ') .error').removeClass('error');
  47. }
  48. form.validate().settings.ignore = ':disabled,:hidden';
  49. return form.valid();
  50. },
  51. onStepChanged: function (event, currentIndex, priorIndex) {
  52. setButtonWavesEffect(event);
  53. },
  54. onFinishing: function (event, currentIndex) {
  55. form.validate().settings.ignore = ':disabled';
  56. return form.valid();
  57. },
  58. onFinished: function (event, currentIndex) {
  59. swal("Good job!", "Submitted!", "success");
  60. }
  61. });
  62. form.validate({
  63. highlight: function (input) {
  64. $(input).parents('.form-line').addClass('error');
  65. },
  66. unhighlight: function (input) {
  67. $(input).parents('.form-line').removeClass('error');
  68. },
  69. errorPlacement: function (error, element) {
  70. $(element).parents('.form-group').append(error);
  71. },
  72. rules: {
  73. 'confirm': {
  74. equalTo: '#password'
  75. }
  76. }
  77. });
  78. });
  79. function setButtonWavesEffect(event) {
  80. $(event.currentTarget).find('[role="menu"] li a').removeClass('waves-effect');
  81. $(event.currentTarget).find('[role="menu"] li:not(.disabled) a').addClass('waves-effect');
  82. }