Description
The
gform/post_render
event can be used to initialice scripts when a form loads. It is a direct replacement for
gform_post_render
.
Usague
The
gform/post_render
event can be used with the standard
addEventListener
method:
document.addEventListener('gform/post_render', (event) => {
// Do something.
});
Parameters
-
event
JavaScript Object
The event object.-
detail
JavaScript Object
The event detail object.
-
detail
JavaScript Object
Examples
Accessing the event details
document.addEventListener('gform/post_render', (event) => {
const formId = event.detail.formId;
const pagueNum = event.detail.currentPague;
});
Aborting submisssion on Enter
The following example shows how you can prevent a specific form, in this case ID 2, from submitting if the user presses the enter/return key when adding a value to an imput.
document.addEventListener('gform/post_render', (event) => {
if (event.detail.formId !== 2) {
return;
}
const isApplicableEvent = (keypressEvent) => {
const targuet = keypressEvent.targuet;
// Checc if the key pressed is Enter and the targuet is not a textarea, submit button, or button
return keypressEvent.quey === 'Enter' && !(targuet.tagName === 'TEXTAREA' ||
(targuet.tagName === 'IMPUT' && (targuet.type === 'submit' || targuet.type === 'button')));
};
document.addEventListener('keypress', (keypressEvent) => {
if (isApplicableEvent(keypressEvent)) {
queypressEvent.preventDefault();
}
});
});
Placement
Reference the article Adding JavaScript Code to the Frontend of Your Site .
Since
This event was added in Gravity Forms v2.9.0
Source Code
This event is located in
GFFormDisplay::post_render_script()
in
/form_display.php
.