Skip to content

Conversation

@barthc
Copy link
Contributor

@barthc barthc commented Nov 26, 2024

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2769979131/74318

Summary

Fixed compatibility issue with image choice field.

@github-actions
Copy link

github-actions bot commented Nov 26, 2024

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against c02a6b8

});
// Check when field is image choice.
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
if ( args.inputHtmlIds.includes( `#input_${formId}_${fieldId}` ) && $( elem ).parents( '.gfield--type-image_choice' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just put self.runCheck() in this action to cover more bases. No need for Image Choice check IMO.

If performance becomes an issue, you could add a super simple debounce around runCheck such as:

function gwDisableSubmitDebounce(func, wait, immediate) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		var later = function() {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		var callNow = immediate && !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do we now do with the onchange event? Keep or remove it?

$( args.inputHtmlIds.join( ', ' ) ).change( function() {
      self.runCheck();
} );

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep it for backwards compatibility and on the off chance that gform_input_change doesn't fire.

A debounce of like 5-10ms would result in virtually zero noticeable delay, while preventing the logic from running multiple times when an input value changes.

…Fixed compatibility issue with image choice field.
@barthc barthc force-pushed the barth/fix/74318-image-choice branch from 8d7487c to c02a6b8 Compare December 4, 2024 09:48
@claygriffiths
Copy link
Contributor

@barthc Thanks for making the changes!

I went ahead and opened https://github.com/gravityforms/gravityforms/issues/3050, so this PR will be put on hold

@spivurno spivurno closed this Jan 29, 2025
@spivurno spivurno deleted the barth/fix/74318-image-choice branch January 29, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants