| @@ -267,8 +267,13 @@ | ||
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | + var dateInput = document.querySelector('.yatra-search-date-input'); | |
| 272 | + if (dateInput && dateInput.value && /^\d{4}-\d{2}-\d{2}$/.test(dateInput.value)) { | |
| 273 | + filters.available_date = dateInput.value; | |
| 274 | + } | |
| 275 | + | |
| 271 | 276 | var listing = getListingUrl(); |
| 272 | 277 | var url; |
| 273 | 278 | try { |
| 274 | 279 | url = new URL(listing); |
| @@ -305,8 +310,34 @@ | ||
| 305 | 310 | }); |
| 306 | 311 | } |
| 307 | 312 | } |
| 308 | 313 | |
| 314 | + // Upgrade the native date field to the same flatpickr picker used on the | |
| 315 | + // checkout/booking page, for a consistent, styled calendar. Fully guarded: | |
| 316 | + // with no flatpickr (or on mobile, where the native picker is already good) | |
| 317 | + // the native <input type="date"> is left working untouched. The submitted | |
| 318 | + // value stays ISO (Y-m-d) so the search URL and back-end are unchanged. | |
| 319 | + function initTripSearchDatePicker() { | |
| 320 | + var input = document.querySelector('.yatra-search-date-input'); | |
| 321 | + if (!input || input.dataset.yatraFp === '1') return; | |
| 322 | + if (typeof window.flatpickr === 'undefined') return; | |
| 323 | + var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent || ''); | |
| 324 | + if (isMobile) return; // native mobile date UI is already good; leave it | |
| 325 | + input.dataset.yatraFp = '1'; | |
| 326 | + // Switch off the native date UI so flatpickr is the only picker; the | |
| 327 | + // value stays ISO (Y-m-d) via dateFormat, so runTripSearch() and the | |
| 328 | + // back-end see the same format as before. | |
| 329 | + try { input.type = 'text'; } catch (e) {} | |
| 330 | + window.flatpickr(input, { | |
| 331 | + dateFormat: 'Y-m-d', | |
| 332 | + minDate: input.getAttribute('min') || 'today', | |
| 333 | + defaultDate: input.value || null, | |
| 334 | + allowInput: false, | |
| 335 | + disableMobile: true | |
| 336 | + }); | |
| 337 | + } | |
| 338 | + | |
| 309 | 339 | initHorizontalSearchDropdowns(); |
| 310 | 340 | initDurationSlider(); |
| 311 | 341 | initSearchFunctionality(); |
| 342 | + initTripSearchDatePicker(); | |
| 312 | 343 | }); |