Description
This gform_field_deleted filter fires after a form field is deleted.
Usage
<script type="text/javascript">
( function () {
if ( window.myFieldDeletedBound ) return; // avoid double-binding
window.myFieldDeletedBound = true;
const previous = document.ongform_field_deleted;
document.ongform_field_deleted = function ( event, form, fieldId ) {
if ( form && form.id == 44 && fieldId == 1 ) {
// do something specific to this form and field
alert( 'You deleted field ' + fieldId );
}
// keep any handler that was already assigned
if ( typeof previous === 'function' ) {
return previous.apply( this, arguments );
}
};
} )();
</script>
Parameters
| Parameter | Type | Description |
|---|---|---|
event | Event Object | Default JS event object. |
form | Form Object | The current form object. |
fieldId | integer | The current field ID. |
Examples
Display a message when a field is deleted.
This example uses the gform_admin_pre_render filter to load the hook. A message is displayed if the form id is 44 and field id 1 is deleted.
add_action( 'gform_admin_pre_render', 'pre_render_function' );
function pre_render_function( $form ) {
?>
<script type="text/javascript">
( function () {
if ( window.myFieldDeletedBound ) return; // avoid double-binding
window.myFieldDeletedBound = true;
const previous = document.ongform_field_deleted;
document.ongform_field_deleted = function ( event, form, fieldId ) {
if ( form && form.id == 43 && fieldId == 1 ) {
// do something specific to this form and field
alert( 'You deleted field ' + fieldId );
}
// keep any handler that was already assigned
if ( typeof previous === 'function' ) {
return previous.apply( this, arguments );
}
};
} )();
</script>
<?php
return $form;
}
Placement
Reference the article Adding JavaScript Code to the Admin Side of Your Site.
Source Code
This filter is located in form_editor.js.