Last active
June 13, 2023 14:46
-
-
Save coulterpeterson/6c35298be68620c2e312b50536a62c23 to your computer and use it in GitHub Desktop.
Gravity Forms | Automatically Submit After X Number of Characters Entered Into Field
This file contains hidden or 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
/** | |
* Gravity Wiz // Gravity Forms // Automatically Submit After X Number of Characters Entered Into Field | |
* https://gravitywiz.com/ | |
* | |
* Instructions: | |
* | |
* 1. Install this snippet with our free Custom JavaScript plugin. | |
* https://gravitywiz.com/gravity-forms-custom-javascript/ | |
* 2. Replace "1" with the ID of your field, and "4" with the number of characters you want to limit it to. | |
* | |
*/ | |
// When the page is ready | |
window.addEventListener('load', function () { | |
if (document.querySelector('body') !== null) { | |
let characterLimit = 4; | |
let field = document.querySelector('#input_GFFORMID_1'); | |
field.addEventListener('input', checkForCharacterMaxReached()); | |
// Manually check for max reached every half second just in case it gets changed via JavaScript | |
// instead of manual entry | |
let t=setInterval(checkForCharacterMaxReached,500); | |
function checkForCharacterMaxReached() { | |
if( field.value.length >= characterLimit ) { | |
document.querySelector('form#gform_GFFORMID').submit(); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment