Created
December 26, 2013 17:11
-
-
Save richardW8k/8136177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
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
Indeed, does not work for me either