gform.utils

Introduction

The gform.utils object in Gravity Forms provides a collection of utility functions and modules to assist developers in performing common tasks such as DOM manipulation, data processing, browser compatibility, etc.

Note: You can access comprehensive documentation for gform.utils at: https://docs.js.gravity.com/js-utils/

Overview

NameTypeDescription
addAsyncFilterFunctionAdds an asynchronous filter for event-driven processing.
addFilterFunctionAdds a synchronous filter for event-driven processing.
animateModuleProvides animation-related utilities.
applyBrowserClassesFunctionApplies browser-specific classes to the DOM for styling or scripting purposes.
arrayEqualsFunctionChecks if two arrays are equal.
arrayToIntFunctionConverts an array of values to integers.
aspectRatioToPaddingFunctionConverts an aspect ratio to a padding value for responsive layouts.
bodyLockModuleManages body scroll locking for modal or overlay scenarios.
browsersFunctionDetects browser information for compatibility checks.
checkNotificationPromiseFunctionChecks for notification API support in the browser.
clipboardFunctionInteracts with the system clipboard for copy/paste functionality.
cloneDeepFunctionCreates a deep copy of an object or array.
consoleErrorFunctionLogs an error message to the console with formatting.
consoleInfoFunctionLogs an info message to the console with formatting.
consoleLogFunctionLogs a message to the console with formatting.
consoleWarnFunctionLogs a warning message to the console with formatting.
convertElementsFunctionConverts elements for DOM manipulation or processing.
cookieStorageModuleManages cookie-based storage operations.
debounceFunctionDebounces a function to limit execution frequency.
deepMergeFunctionMerges two objects deeply, preserving nested properties.
delayFunctionDelays execution of a function for a specified time.
delegateFunctionSets up event delegation for efficient event handling.
dragHorizontalFunctionEnables horizontal drag functionality for elements.
escapeHtmlFunctionEscapes HTML characters to prevent XSS or rendering issues.
escapeScriptsFunctionEscapes script tags to prevent execution in unsafe contexts.
filterFunctionFilters an array based on a provided condition.
filterObjectFunctionFilters an object’s properties based on a condition.
findNestedObjectFunctionFinds a nested object by key within a parent object.
fnvHashFunctionGenerates an FNV hash for a given input.
focusLoopFunctionManages focus trapping within a container for accessibility.
getAttachmentImageUrlFunctionRetrieves the URL of an attachment image.
getChildrenFunctionRetrieves child elements of a given DOM node.
getClosestFunctionFinds the closest ancestor element matching a selector.
getConfigFunctionRetrieves configuration settings for a component or module.
getCoordsFunctionGets the coordinates of an element relative to the viewport.
getFocusableFunctionRetrieves focusable elements within a container for accessibility.
getHiddenHeightFunctionCalculates the height of a hidden element.
getNodeFunctionRetrieves a single DOM node based on a selector or reference.
getNodesFunctionRetrieves multiple DOM nodes based on a selector.
hasClassFromArrayFunctionChecks if an element has any class from a provided array.
hasScrollbarFunctionDetects if an element has a visible scrollbar.
insertAfterFunctionInserts an element after a specified target in the DOM.
insertBeforeFunctionInserts an element before a specified target in the DOM.
isEmptyObjectFunctionChecks if an object is empty.
isEqualFunctionCompares two values for equality, including nested structures.
isExternalLinkFunctionDetermines if a URL is an external link.
isFileLinkFunctionChecks if a link points to a file resource.
isFormDirtyFunctionChecks if a form has unsaved changes.
isFunctionFunctionVerifies if a value is a function.
isImageLinkFunctionChecks if a link points to an image resource.
isJestTestFunctionDetects if the code is running in a Jest test environment.
isJsonFunctionValidates if a string is valid JSON.
isNumberFunctionChecks if a value is a number.
isObjectFunctionVerifies if a value is an object.
isRtlFunctionDetects if the document is in right-to-left (RTL) mode.
localStorageModuleManages local storage operations for persistent data.
matchesOrContainedInSelectorsFunctionChecks if an element matches or is contained within provided selectors.
mimicFnFunctionCopies properties and methods from one function to another.
normalizeUrlFunctionNormalizes a URL for consistent formatting.
objectAssignFunctionMerges objects using Object.assign-like functionality.
objectToAttributesFunctionConverts an object to HTML attributes string.
objectToFormDataFunctionConverts an object to FormData for form submissions.
openNewTabFunctionOpens a URL in a new browser tab.
parseUrlFunctionParses a URL into its components.
popupFunctionManages popup window functionality.
queryToJsonFunctionConverts a query string to a JSON object.
readyFunctionExecutes a callback when the DOM is fully loaded.
removeClassThatContainsFunctionRemoves classes from an element that contain a specific string.
removeFilterFunctionRemoves a previously added filter.
resizeFunctionHandles window resize events with throttling.
runOnceFunctionEnsures a function runs only once.
saferHtmlFunctionSanitizes HTML to prevent XSS while allowing safe tags.
sessionStorageModuleManages session storage operations for temporary data.
setAttributesFunctionSets multiple attributes on a DOM element.
shouldLoadChunkFunctionDetermines if a JavaScript chunk should be loaded.
simpleBarModuleProvides custom scrollbar functionality.
slideModuleManages slide animations for elements.
slugifyFunctionConverts a string into a URL-friendly slug.
spacerClassesFunctionGenerates spacer classes for layout control.
speakFunctionUtilizes the Web Speech API for text-to-speech functionality.
sprintfFunctionFormats strings using placeholders, similar to sprintf in PHP.
triggerFunctionTriggers a custom or native DOM event.
uniqueIdFunctionGenerates a unique ID for elements or objects.
updateQueryVarFunctionUpdates a query variable in a URL.
viewportModuleProvides utilities for working with the viewport (e.g., dimensions, scroll position).
visibleFunctionChecks if an element is visible in the DOM.
vsprintfFunctionFormats strings with an array of arguments, similar to vsprintf in PHP.