Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

wizard-ex-property-listing.js 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /**
  2. * Form Wizard
  3. */
  4. 'use strict';
  5. (function () {
  6. // Init custom option check
  7. window.Helpers.initCustomOptionCheck();
  8. const flatpickrRange = document.querySelector('.flatpickr'),
  9. phoneMask = document.querySelector('.contact-number-mask'),
  10. plCountry = $('#plCountry'),
  11. plFurnishingDetailsSuggestionEl = document.querySelector('#plFurnishingDetails');
  12. // Phone Number Input Mask
  13. if (phoneMask) {
  14. phoneMask.addEventListener('input', event => {
  15. const cleanValue = event.target.value.replace(/\D/g, '');
  16. phoneMask.value = formatGeneral(cleanValue, {
  17. blocks: [3, 3, 4],
  18. delimiters: [' ', ' ']
  19. });
  20. });
  21. registerCursorTracker({
  22. input: phoneMask,
  23. delimiter: ' '
  24. });
  25. }
  26. // select2 (Country)
  27. if (plCountry) {
  28. plCountry.wrap('<div class="position-relative"></div>');
  29. plCountry.select2({
  30. placeholder: 'Select country',
  31. dropdownParent: plCountry.parent()
  32. });
  33. }
  34. if (flatpickrRange) {
  35. flatpickrRange.flatpickr();
  36. }
  37. // Tagify (Furnishing details)
  38. const furnishingList = [
  39. 'Fridge',
  40. 'TV',
  41. 'AC',
  42. 'WiFi',
  43. 'RO',
  44. 'Washing Machine',
  45. 'Sofa',
  46. 'Bed',
  47. 'Dining Table',
  48. 'Microwave',
  49. 'Cupboard'
  50. ];
  51. if (plFurnishingDetailsSuggestionEl) {
  52. const plFurnishingDetailsSuggestion = new Tagify(plFurnishingDetailsSuggestionEl, {
  53. whitelist: furnishingList,
  54. maxTags: 9,
  55. dropdown: {
  56. maxItems: 20,
  57. classname: 'tags-inline',
  58. enabled: 0,
  59. closeOnSelect: false
  60. }
  61. });
  62. }
  63. // Vertical Wizard
  64. // --------------------------------------------------------------------
  65. const wizardPropertyListing = document.querySelector('#wizard-property-listing');
  66. if (typeof wizardPropertyListing !== undefined && wizardPropertyListing !== null) {
  67. // Wizard form
  68. const wizardPropertyListingForm = wizardPropertyListing.querySelector('#wizard-property-listing-form');
  69. // Wizard steps
  70. const wizardPropertyListingFormStep1 = wizardPropertyListingForm.querySelector('#personal-details');
  71. const wizardPropertyListingFormStep2 = wizardPropertyListingForm.querySelector('#property-details');
  72. const wizardPropertyListingFormStep3 = wizardPropertyListingForm.querySelector('#property-features');
  73. const wizardPropertyListingFormStep4 = wizardPropertyListingForm.querySelector('#property-area');
  74. const wizardPropertyListingFormStep5 = wizardPropertyListingForm.querySelector('#price-details');
  75. // Wizard next prev button
  76. const wizardPropertyListingNext = [].slice.call(wizardPropertyListingForm.querySelectorAll('.btn-next'));
  77. const wizardPropertyListingPrev = [].slice.call(wizardPropertyListingForm.querySelectorAll('.btn-prev'));
  78. const validationStepper = new Stepper(wizardPropertyListing, {
  79. linear: true
  80. });
  81. // Personal Details
  82. const FormValidation1 = FormValidation.formValidation(wizardPropertyListingFormStep1, {
  83. fields: {
  84. // * Validate the fields here based on your requirements
  85. plFirstName: {
  86. validators: {
  87. notEmpty: {
  88. message: 'Please enter your first name'
  89. }
  90. }
  91. },
  92. plLastName: {
  93. validators: {
  94. notEmpty: {
  95. message: 'Please enter your last name'
  96. }
  97. }
  98. }
  99. },
  100. plugins: {
  101. trigger: new FormValidation.plugins.Trigger(),
  102. bootstrap5: new FormValidation.plugins.Bootstrap5({
  103. // Use this for enabling/changing valid/invalid class
  104. // eleInvalidClass: '',
  105. eleValidClass: '',
  106. rowSelector: '.form-control-validation'
  107. }),
  108. autoFocus: new FormValidation.plugins.AutoFocus(),
  109. submitButton: new FormValidation.plugins.SubmitButton()
  110. },
  111. init: instance => {
  112. instance.on('plugins.message.placed', function (e) {
  113. //* Move the error message out of the `input-group` element
  114. if (e.element.parentElement.classList.contains('input-group')) {
  115. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  116. }
  117. });
  118. }
  119. }).on('core.form.valid', function () {
  120. // Jump to the next step when all fields in the current step are valid
  121. validationStepper.next();
  122. });
  123. // Property Details
  124. const FormValidation2 = FormValidation.formValidation(wizardPropertyListingFormStep2, {
  125. fields: {
  126. // * Validate the fields here based on your requirements
  127. plPropertyType: {
  128. validators: {
  129. notEmpty: {
  130. message: 'Please select property type'
  131. }
  132. }
  133. },
  134. plZipCode: {
  135. validators: {
  136. notEmpty: {
  137. message: 'Please enter zip code'
  138. },
  139. stringLength: {
  140. min: 4,
  141. max: 10,
  142. message: 'The zip code must be more than 4 and less than 10 characters long'
  143. }
  144. }
  145. }
  146. },
  147. plugins: {
  148. trigger: new FormValidation.plugins.Trigger(),
  149. bootstrap5: new FormValidation.plugins.Bootstrap5({
  150. // Use this for enabling/changing valid/invalid class
  151. // eleInvalidClass: '',
  152. eleValidClass: '',
  153. rowSelector: function (field, ele) {
  154. // field is the field name & ele is the field element
  155. switch (field) {
  156. case 'plAddress':
  157. return '.form-control-validation';
  158. default:
  159. return '.form-control-validation';
  160. }
  161. }
  162. }),
  163. autoFocus: new FormValidation.plugins.AutoFocus(),
  164. submitButton: new FormValidation.plugins.SubmitButton()
  165. }
  166. }).on('core.form.valid', function () {
  167. // Jump to the next step when all fields in the current step are valid
  168. validationStepper.next();
  169. });
  170. // select2 (Property type)
  171. const plPropertyType = $('#plPropertyType');
  172. if (plPropertyType.length) {
  173. plPropertyType.wrap('<div class="position-relative"></div>');
  174. plPropertyType
  175. .select2({
  176. placeholder: 'Select property type',
  177. dropdownParent: plPropertyType.parent()
  178. })
  179. .on('change', function () {
  180. // Revalidate the color field when an option is chosen
  181. FormValidation2.revalidateField('plPropertyType');
  182. });
  183. }
  184. // Property Features
  185. const FormValidation3 = FormValidation.formValidation(wizardPropertyListingFormStep3, {
  186. fields: {
  187. // * Validate the fields here based on your requirements
  188. },
  189. plugins: {
  190. trigger: new FormValidation.plugins.Trigger(),
  191. bootstrap5: new FormValidation.plugins.Bootstrap5({
  192. // Use this for enabling/changing valid/invalid class
  193. // eleInvalidClass: '',
  194. eleValidClass: '',
  195. rowSelector: '.form-control-validation'
  196. }),
  197. autoFocus: new FormValidation.plugins.AutoFocus(),
  198. submitButton: new FormValidation.plugins.SubmitButton()
  199. }
  200. }).on('core.form.valid', function () {
  201. validationStepper.next();
  202. });
  203. // Property Area
  204. const FormValidation4 = FormValidation.formValidation(wizardPropertyListingFormStep4, {
  205. fields: {
  206. // * Validate the fields here based on your requirements
  207. },
  208. plugins: {
  209. trigger: new FormValidation.plugins.Trigger(),
  210. bootstrap5: new FormValidation.plugins.Bootstrap5({
  211. // Use this for enabling/changing valid/invalid class
  212. // eleInvalidClass: '',
  213. eleValidClass: '',
  214. rowSelector: '.form-control-validation'
  215. }),
  216. autoFocus: new FormValidation.plugins.AutoFocus(),
  217. submitButton: new FormValidation.plugins.SubmitButton()
  218. }
  219. }).on('core.form.valid', function () {
  220. // Jump to the next step when all fields in the current step are valid
  221. validationStepper.next();
  222. });
  223. // Price Details
  224. const FormValidation5 = FormValidation.formValidation(wizardPropertyListingFormStep5, {
  225. fields: {
  226. // * Validate the fields here based on your requirements
  227. },
  228. plugins: {
  229. trigger: new FormValidation.plugins.Trigger(),
  230. bootstrap5: new FormValidation.plugins.Bootstrap5({
  231. // Use this for enabling/changing valid/invalid class
  232. // eleInvalidClass: '',
  233. eleValidClass: '',
  234. rowSelector: '.form-control-validation'
  235. }),
  236. autoFocus: new FormValidation.plugins.AutoFocus(),
  237. submitButton: new FormValidation.plugins.SubmitButton()
  238. }
  239. }).on('core.form.valid', function () {
  240. // You can submit the form
  241. // wizardPropertyListingForm.submit()
  242. // or send the form data to server via an Ajax request
  243. // To make the demo simple, I just placed an alert
  244. alert('Submitted..!!');
  245. });
  246. wizardPropertyListingNext.forEach(item => {
  247. item.addEventListener('click', event => {
  248. // When click the Next button, we will validate the current step
  249. switch (validationStepper._currentIndex) {
  250. case 0:
  251. FormValidation1.validate();
  252. break;
  253. case 1:
  254. FormValidation2.validate();
  255. break;
  256. case 2:
  257. FormValidation3.validate();
  258. break;
  259. case 3:
  260. FormValidation4.validate();
  261. break;
  262. case 4:
  263. FormValidation5.validate();
  264. break;
  265. default:
  266. break;
  267. }
  268. });
  269. });
  270. wizardPropertyListingPrev.forEach(item => {
  271. item.addEventListener('click', event => {
  272. switch (validationStepper._currentIndex) {
  273. case 4:
  274. validationStepper.previous();
  275. break;
  276. case 3:
  277. validationStepper.previous();
  278. break;
  279. case 2:
  280. validationStepper.previous();
  281. break;
  282. case 1:
  283. validationStepper.previous();
  284. break;
  285. case 0:
  286. default:
  287. break;
  288. }
  289. });
  290. });
  291. }
  292. })();