This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Alter the datepicker options before they are converted to javascript.
Usage
add_filter( 'frm_date_field_options', 'my_custom_function', 20, 2 );
Parameters
- $date_options (array)
- $args (array)
- $args['field_id'] (string) - The HTML id for this field
- $args['options'] (array) - The settings for this field
Examples
Blackout dynamic dates
This example will Blackout the New Years day when the Datepicker Options plugin is used.
add_filter( 'frm_date_field_options', 'add_blackout_dates', 30, 2 );
function add_blackout_dates( $js_options, $extra ) {
if ( $extra['field_id'] === 'field_jtumj' ) { // Replace jtumj with your field key
$js_options['formidable_dates']['datesDisabled'][] = date( 'Y-m-d', strtotime( 'first day of january' ) );
}
return $js_options;
}
Hide month and year selectors
By default, the month and year are displayed in dropdown lists. By using this code, it will allow you to show the month and year in the calendar display header and have users select dates by using the next/previous buttons.
add_filter( 'frm_date_field_options', 'hide_month_and_year', 30, 2 );
function hide_month_and_year( $js_options, $extra ) {
if ( $extra['field_id'] === 'field_jtumj' ) { // Replace jtumj with your field key
$js_options['options']['changeMonth'] = false;
$js_options['options']['changeYear'] = false;
}
return $js_options;
}
Add calendar icon to field
This example adds a clickable calendar icon next to a date field. When the icon is clicked, it will pull up the calendar. It is recommended to move the icon image to your site's images folder and adjust the path in the code. You can change the icon to any image in your site's images folder.
add_filter( 'frm_date_field_options', 'add_cal_icon', 30, 2 );
function add_cal_icon( $js_options, $extra ) {
if ( $extra['field_id'] === 'field_jtumj' ) { // Replace jtumj with your field key
$js_options['options']['showOn'] = 'button';
$js_options['options']['buttonImage'] = 'http://jqueryui.com/resources/demos/datepicker/images/calendar.gif';
$js_options['options']['buttonImageOnly'] = true;
}
return $js_options;
}