jQuery plugin for date and time selection combining both date picker and time picker functionality with extensive customization and internationalization support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Methods available on individual datetimepicker instances for programmatic control and value access.
Retrieve the current datetime value from the picker instance.
/**
* Get the current datetime value from the picker
* @returns Current datetime as Date object or null if no value
*/
getValue(): Date | null;Usage Examples:
// Get picker instance and retrieve value
var picker = $('#myinput').datetimepicker().data('xdsoft_datetimepicker');
var currentValue = picker.getValue();
if (currentValue) {
console.log('Selected date:', currentValue.toISOString());
} else {
console.log('No date selected');
}
// Get value after user selection
$('#myinput').datetimepicker({
onSelectDate: function(current_time, input) {
var picker = $(input).data('xdsoft_datetimepicker');
var value = picker.getValue();
console.log('Date selected:', value);
}
});Update picker configuration options after initialization.
/**
* Update picker options after initialization
* @param options - New options to apply
* @returns void
*/
setOptions(options: Partial<DateTimePickerOptions>): void;Usage Examples:
// Initialize picker
var picker = $('#myinput').datetimepicker().data('xdsoft_datetimepicker');
// Update options dynamically
picker.setOptions({
format: 'Y-m-d',
timepicker: false
});
// Change constraints based on other inputs
$('#startDate').on('change', function() {
var startDate = $(this).val();
var endPicker = $('#endDate').data('xdsoft_datetimepicker');
endPicker.setOptions({
minDate: startDate
});
});
// Toggle between date and datetime modes
$('#modeToggle').on('change', function() {
var isDateOnly = $(this).is(':checked');
var picker = $('#myinput').data('xdsoft_datetimepicker');
picker.setOptions({
timepicker: !isDateOnly,
format: isDateOnly ? 'Y-m-d' : 'Y-m-d H:i'
});
});Different ways to access and use instance methods.
Usage Examples:
// Method 1: Get instance from data attribute
var instance = $('#myinput').datetimepicker().data('xdsoft_datetimepicker');
var value = instance.getValue();
instance.setOptions({ step: 15 });
// Method 2: Chain access during initialization
$('#myinput').datetimepicker({
onShow: function() {
var picker = $(this).data('xdsoft_datetimepicker');
console.log('Current value:', picker.getValue());
}
});
// Method 3: Access in event callbacks
$('#myinput').datetimepicker({
onChangeDateTime: function(currentTime, input) {
var picker = $(input).data('xdsoft_datetimepicker');
// Update other pickers based on this value
if (currentTime) {
var nextDay = new Date(currentTime);
nextDay.setDate(nextDay.getDate() + 1);
$('#endDate').data('xdsoft_datetimepicker').setOptions({
minDate: nextDay
});
}
}
});
// Method 4: Store reference for later use
var myPicker = $('#myinput').datetimepicker().data('xdsoft_datetimepicker');
// Use stored reference
$('#updateBtn').click(function() {
myPicker.setOptions({
maxDate: new Date()
});
});
$('#getValueBtn').click(function() {
var value = myPicker.getValue();
$('#display').text(value ? value.toString() : 'No value');
});Common patterns for working with instance methods.
Usage Examples:
// Validation with instance methods
function validateDateRange() {
var startPicker = $('#startDate').data('xdsoft_datetimepicker');
var endPicker = $('#endDate').data('xdsoft_datetimepicker');
var startValue = startPicker.getValue();
var endValue = endPicker.getValue();
if (startValue && endValue && startValue > endValue) {
alert('Start date must be before end date');
return false;
}
return true;
}
// Dynamic option updates based on business logic
function updatePickerConstraints(userRole) {
var picker = $('#appointmentDate').data('xdsoft_datetimepicker');
if (userRole === 'admin') {
picker.setOptions({
minDate: false,
maxDate: false,
disabledDates: []
});
} else {
picker.setOptions({
minDate: new Date(),
maxDate: new Date(Date.now() + 30*24*60*60*1000), // 30 days
disabledWeekDays: [0, 6] // No weekends
});
}
}
// Sync multiple pickers
function createLinkedPickers() {
$('#startTime').datetimepicker({
format: 'Y-m-d H:i',
onChangeDateTime: function(currentTime, input) {
if (currentTime) {
var endPicker = $('#endTime').data('xdsoft_datetimepicker');
endPicker.setOptions({
minDateTime: currentTime
});
}
}
});
$('#endTime').datetimepicker({
format: 'Y-m-d H:i',
onChangeDateTime: function(currentTime, input) {
if (currentTime) {
var startPicker = $('#startTime').data('xdsoft_datetimepicker');
startPicker.setOptions({
maxDateTime: currentTime
});
}
}
});
}Handle cases where instance methods might fail.
Usage Examples:
// Safe instance access
function safeGetValue(selector) {
try {
var picker = $(selector).data('xdsoft_datetimepicker');
if (picker && typeof picker.getValue === 'function') {
return picker.getValue();
}
} catch (e) {
console.warn('Could not get value from picker:', e);
}
return null;
}
// Safe option updates
function safeSetOptions(selector, options) {
try {
var picker = $(selector).data('xdsoft_datetimepicker');
if (picker && typeof picker.setOptions === 'function') {
picker.setOptions(options);
return true;
}
} catch (e) {
console.warn('Could not update picker options:', e);
}
return false;
}
// Check if picker is initialized
function isPickerInitialized(selector) {
var picker = $(selector).data('xdsoft_datetimepicker');
return picker && typeof picker.getValue === 'function';
}