Skip to content

gpld-populate-new-minimum-date-into-linked-date-field.js: Fixed an issue with default value of field notgetting used to apply minimum date. #1099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@
* 1. Install this snippet with our free Custom JavaScript plugin.
* https://gravitywiz.com/gravity-forms-code-chest/
*/
gform.addAction( 'gpld_after_set_min_date', function( $input, date ) {
$input.datepicker( 'setDate', date );
const sourceFieldId = 25; // Replace with the ID of the source field (Field A)

// Initialize field events on form render.
document.addEventListener( 'gform/post_render', (event) => {
const formId = event.detail.formId;
const $field = getSourceField(formId, sourceFieldId);
triggerFieldEventsIfValueExists($field);
});

// Handle conditional logic changes.
gform.addAction(
'gform_post_conditional_logic_field_action',
(formId, action, targetId, defaultValues, isInit) => {
// Only for fields and when we are not hiding them.
if (action == 'hide' || targetId == '#gform_submit_button_' + formId) {
return;
}

const $field = getSourceField(formId, sourceFieldId);
triggerFieldEventsIfValueExists($field);
}
);

// Triggers input and change events on a field if it has a value.
const triggerFieldEventsIfValueExists = ($field) => {
const value = $field.val();
if (value) {
requestAnimationFrame(() => {
$field.trigger('input').trigger('change');
});
}
};

// Get the source field based on form ID and field ID.
const getSourceField = (formId, fieldId) => {
return jQuery(`#input_${formId}_${fieldId}`);
};

gform.addAction( 'gpld_after_set_min_date', function( $input, date ) {
$input.datepicker( 'setDate', date );
} );
Loading