Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save coulterpeterson/6c35298be68620c2e312b50536a62c23 to your computer and use it in GitHub Desktop.
Save coulterpeterson/6c35298be68620c2e312b50536a62c23 to your computer and use it in GitHub Desktop.
Gravity Forms | Automatically Submit After X Number of Characters Entered Into Field
/**
* 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