Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Created December 26, 2013 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/8136177 to your computer and use it in GitHub Desktop.
Save richardW8k/8136177 to your computer and use it in GitHub Desktop.
function listFieldDatepicker(formId, fieldId, column) {
var listField = '#field_' + formId + '_' + fieldId,
columnClass = '.gfield_list_' + fieldId + '_cell' + column + ' input';
jQuery.datepicker.setDefaults({
showOn: 'both',
buttonImage: '/wp-content/plugins/gravityforms/images/calendar.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
firstDay: 1
});
jQuery(columnClass).css({'width': '80%', 'margin-right': '2px'}).datepicker();
jQuery(listField).on('click', '.add_list_item', function () {
jQuery('.ui-datepicker-trigger').remove();
jQuery(columnClass).removeClass('hasDatepicker').removeAttr('id').datepicker();
});
}
listFieldDatepicker(140, 1, 3);
//listFieldDatepicker(form id, list field id, list field column number);
@soniklee
Copy link

soniklee commented Apr 5, 2021

Indeed, does not work for me either

@Godislife
Copy link

Make sure the "jQuery UI date picker" script is loaded otherwise you will have errors when the datepicker.setDefaults is called and the above script will not work. The error most likely when you do an inspect on your page console will be "Uncaught TypeError: Cannot read properties of undefined (reading 'setDefaults')".

Since GF loads that script with date fields you don't want to load it manually to avoid conflicts. You can add a hidden date field with the form unless you already have a date picker field in the form available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment