Skip to content
Merged
Changes from 1 commit
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,17 @@
* 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)
document.addEventListener( 'gform/post_render', ( event ) => {
const $field = jQuery( `#input_GFFORMID_${sourceFieldId}` );
const value = $field.val();
if ( value ) {
requestAnimationFrame( function(){
$field.trigger( 'input' ).trigger( 'change' );
});
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for field selection

The code assumes the field will always be found, but this may not be true if the field ID is incorrect or the field is conditionally hidden. Consider adding error handling.

	const $field = jQuery( `#input_GFFORMID_${sourceFieldId}` );
+	if ($field.length === 0) {
+		console.error(`Source field with ID ${sourceFieldId} not found. Please check the field ID.`);
+		return;
+	}
	const value  = $field.val();
	if ( value ) {
		requestAnimationFrame( function(){
			$field.trigger( 'input' ).trigger( 'change' );
		});
	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const value = $field.val();
if ( value ) {
requestAnimationFrame( function(){
$field.trigger( 'input' ).trigger( 'change' );
});
}
const $field = jQuery( `#input_GFFORMID_${sourceFieldId}` );
if ($field.length === 0) {
console.error(`Source field with ID ${sourceFieldId} not found. Please check the field ID.`);
return;
}
const value = $field.val();
if ( value ) {
requestAnimationFrame( function(){
$field.trigger( 'input' ).trigger( 'change' );
});
}

});

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