Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions gp-entry-blocks/gpeb-use-select-for-country-filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Gravity Perks // Entry Blocks // Filters Block: Use Select for Country Input Filter
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
*
* Experimental Snippet 🧪
*
* All input fields in the Entry Blocks filter are text inputs by default. This snippet changes the input type to a
* select for the Address field's Country input.
*/
add_filter( 'gpeb_filter_form_field', function ( $field ) {
if ( ! rgar( $field, 'gpebFilterInputField' ) ) {
return $field;
}

$input_field = $field['gpebFilterInputField'];

// If we're not working with an Address field, return the field as-is.
if ( $input_field['type'] !== 'address' ) {
return $field;
}

// Get the input ID.
$input_id = explode( '.', rgar( $field, 'gpebFilterSearch' ) )[1];

switch ( $input_id ) {
// Country
case 6:
$country_choices = array_map( function ( $country ) {
return array(
'text' => $country,
'value' => $country,
);
}, $field['gpebFilterInputField']->get_countries() );

// Change the field to a select and populate it with countries from the address field.
$new_field = new \GF_Field_Select( array(
'id' => $field['id'],
'label' => $field['label'],
'gpebFilterSearch' => $field['gpebFilterSearch'],
'gpebFilterInputField' => $field['gpebFilterInputField'],
'size' => $field['size'],
'inputs' => $field['inputs'],
'formId' => $field['formId'],
'type' => 'select',
'choices' => $country_choices,
) );
return $new_field;
}

return $field;
} );
Loading