form-wizard.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. (function($) {
  2. "use strict";
  3. // WIZARD 1
  4. $('#wizard1').steps({
  5. headerTag: 'h3',
  6. bodyTag: 'section',
  7. autoFocus: true,
  8. titleTemplate: '<span class="number">#index#<\/span> <span class="title">#title#<\/span>'
  9. });
  10. // WIZARD 2
  11. $('#wizard2').steps({
  12. headerTag: 'h3',
  13. bodyTag: 'section',
  14. autoFocus: true,
  15. titleTemplate: '<span class="number">#index#<\/span> <span class="title">#title#<\/span>',
  16. onStepChanging: function(event, currentIndex, newIndex) {
  17. if (currentIndex < newIndex) {
  18. // Step 1 form validation
  19. if (currentIndex === 0) {
  20. var fname = $('#firstname').parsley();
  21. var lname = $('#lastname').parsley();
  22. if (fname.isValid() && lname.isValid()) {
  23. return true;
  24. } else {
  25. fname.validate();
  26. lname.validate();
  27. }
  28. }
  29. // Step 2 form validation
  30. if (currentIndex === 1) {
  31. var email = $('#email').parsley();
  32. if (email.isValid()) {
  33. return true;
  34. } else {
  35. email.validate();
  36. }
  37. }
  38. // Always allow step back to the previous step even if the current step is not valid.
  39. } else {
  40. return true;
  41. }
  42. }
  43. });
  44. // WIZARD 3
  45. $('#wizard3').steps({
  46. headerTag: 'h3',
  47. bodyTag: 'section',
  48. autoFocus: true,
  49. titleTemplate: '<span class="number">#index#<\/span> <span class="title">#title#<\/span>',
  50. stepsOrientation: 1
  51. });
  52. // DROPIFY
  53. $('.dropify-clear').on('click', function () {
  54. $('.dropify-render img').remove();
  55. $(".dropify-preview").css("display", "none");
  56. $(".dropify-clear").css("display", "none");
  57. });
  58. // ACCORDION WIZARD
  59. var options = {
  60. mode: 'wizard',
  61. autoButtonsNextClass: 'btn btn-primary float-end',
  62. autoButtonsPrevClass: 'btn btn-light',
  63. stepNumberClass: 'badge rounded-pill bg-primary me-1',
  64. onSubmit: function() {
  65. alert('Form submitted!');
  66. return true;
  67. }
  68. }
  69. $("#form").accWizard(options);
  70. })(jQuery);
  71. //Function to show image before upload
  72. function readURL(input) {
  73. 'use strict'
  74. if (input.files && input.files[0]) {
  75. var reader = new FileReader();
  76. reader.onload = function(e) {
  77. $('.dropify-render img').remove();
  78. var img = $('<img id="dropify-img">'); //Equivalent: $(document.createElement('img'))
  79. img.attr('src', e.target.result);
  80. img.appendTo('.dropify-render');
  81. $(".dropify-preview").css("display", "block");
  82. $(".dropify-clear").css("display", "block");
  83. };
  84. reader.readAsDataURL(input.files[0]);
  85. }
  86. }