Event callbacks allow you to validate selections, block invalid dates, adjust selections automatically, and respond to user interactions with custom logic.

Before Date Select Callback

Validate and control date selection

Live Demo
Code Examples
JavaScript
 
HTML
 
Details
What It Does

The beforeDateSelectCallback is called BEFORE a date selection is finalized, allowing you to:

  • Validate: Check if selection meets business rules
  • Block: Prevent invalid selections with a message
  • Adjust: Modify the selection before applying
  • Async: Make API calls for validation
Callback Parameters

The callback receives a selection object:

  • type - 'single' or 'range'
  • startDate - Selected/start date (Date object)
  • endDate - End date for ranges (Date object or null)
  • picker - The picker instance
Return Values
  • { action: 'accept' } - Allow selection
  • { action: 'block', message?: string } - Block with optional message
  • { action: 'adjust', startDate, endDate? } - Modify selection
Breaking Change in v1.2.0: This callback was renamed from beforeDateSelect to beforeDateSelectCallback for consistency.

Adjusting Selections

Automatically modify user selections

Live Demo
Code Examples
JavaScript
 
Details
Automatic Adjustments

You can automatically modify user selections to match business rules or improve user experience:

  • Snap to weeks: Adjust to full week boundaries
  • Minimum stays: Extend short selections to minimum length
  • Checkout dates: Ensure checkout is on specific days
  • Business rules: Any custom date adjustment logic
Return Format for Adjustments
return {
  action: 'adjust',
  startDate: new Date(...), // Adjusted start
  endDate: new Date(...)    // Adjusted end (for ranges)
};
Common Use Cases
  • Week rentals: Force Saturday-Saturday bookings
  • Minimum stays: Extend 1-night stays to 2+ nights
  • Holiday adjustments: Avoid checkout on holidays
Tip: Show users a message explaining why their selection was adjusted to improve UX and avoid confusion.

Async Validation

Validate selections with API calls

Live Demo
Code Examples
JavaScript
 
Details
Async Validation

The callback can be async, allowing you to make API calls to validate selections before accepting them:

  • Check availability: Verify dates are bookable
  • Fetch pricing: Calculate total price
  • Validate rules: Check blackout dates, restrictions
  • Get inventory: Ensure sufficient stock/rooms
Loading States

The picker shows a loading overlay automatically during async operations, preventing users from clicking while validation is in progress.

Best Practices
  • Keep API calls fast (<500ms) for good UX
  • Show clear messages explaining why selections were blocked
  • Cache results to avoid redundant API calls
  • Use beforeMonthChangedCallback to pre-load availability data
Pro Tip: Combine beforeMonthChangedCallback (bulk data loading) with beforeDateSelectCallback (final validation) for optimal performance.

onSelect Event

React to completed selections

Live Demo
Code Examples
JavaScript
 
HTML
 
Details
What It Does

The onSelect callback is called AFTER a selection is finalized and accepted (after beforeDateSelectCallback validation passes).

Use Cases
  • Update UI: Show selection summary, pricing, etc.
  • Form integration: Populate hidden form fields
  • Analytics: Track user selections
  • Navigation: Auto-advance to next step
Callback vs Validation
CallbackWhenPurpose
beforeDateSelectCallbackBEFOREValidate, block, adjust
onSelectAFTERReact, update UI
Note: onSelect is called for both single and range mode. Check selection.type to determine the mode.