Description
The gform_load_bulk_choices_choice filter allows each of the current fields choices to be overridden as they are loaded into the Bulk Add Predefined Choices UI.
This filter is generally used in combination with gform_insert_bulk_choices_choice, and is useful for generating unique text patterns for adding arbitrary data to a choice.
Usage
The filter which would run for all forms and choice based fields that support the Bulk Add Predefined Choices UI would be used like so:
gform.addFilter( 'gform_load_bulk_choices_choice', function( choice, choiceObj, field ) { // do stuff return choice; } );
Parameters
- choice string
The string representing the current choice as a text pattern usually in the format text|value e.g.
One|1
- choiceObj Javascript Object
The object representing the choice currently being added to the Bulk Add Predefined Choices UI e.g.
{ "text": "One", "value": "1", "isSelected": false, "price": "" }
This can also include custom choice properties.
-
field Javascript Object | Field Object
The current field.
Examples
1. Append custom choice property
This example shows how you can append a custom choice property to the default text|value format.
gform.addFilter( 'gform_load_bulk_choices_choice', function( choice, choiceObj, field ) { if ( choiceObj.mycustomprop ) { return choice + '|' + choiceObj.mycustomprop; } return choice; } );
Placement
This code should be placed in a JavaScript file included in the admin by your plugin.
Since
This filter was added in Gravity Forms v2.5.
Source Code
This filter is located in LoadBulkChoices() in form_editor.js.