GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
search-field-chainedselect.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Display the Chained Selects input field for the search widget.
4  *
5  * TODO:
6  *
7  * - [ ] When using Chained Select, it only works well when "All"
8  *
9  * @file class-search-widget.php See for usage
10  */
11 
13 $view_id = $gravityview_view->getViewId();
15 
16 if ( ! class_exists( 'GF_Chained_Field_Select' ) ) {
17  gravityview()->log->error( 'The Gravity Forms Chained Select Add-On is not active.' );
18  return;
19 }
20 
21 // Make sure that there are choices to display
22 if( empty( $search_field['choices'] ) ) {
23  gravityview()->log->debug( 'search-field-chainedselect.php - No choices for field' );
24  return;
25 }
26 
28 
30 
31 /** @var GF_Chained_Field_Select $gf_field */
32 $gf_field = $field->field;
33 
34 /**
35  * Prevent Chained Select Search Bar input fields from outputting styles.
36  * @since TODO
37  * @param GravityView_Widget_Search $this GravityView Widget instance
38  * @param array{key:string,label:string,value:string,type:string,choices:array} $search_field
39  */
40 $alignment = apply_filters( 'gravityview/search/chained_selects/alignment', $gravityview_view->search_layout, $search_field );
41 
42 /**
43  * Choose whether to hide inactive dropdowns in the chain.
44  * @since TODO
45  * @param bool $hide_inactive Whether to hide drop-downs that aren't available yet.
46  * @param GravityView_Widget_Search $this GravityView Widget instance
47  * @param array{key:string,label:string,value:string,type:string,choices:array} $search_field
48  */
49 $hide_inactive = apply_filters( 'gravityview/search/chained_selects/hide_inactive', false, $search_field );
50 
51 // Set horizontal/vertical alignment
52 $gf_field->chainedSelectsAlignment = $gravityview_view->search_layout;
53 ?>
54 <div class="gv-search-box gv-search-field-chainedselect">
55  <?php if( ! gv_empty( $search_field['label'], false, false ) ) { ?>
56  <label for="search-box-<?php echo esc_attr( $search_field['name'] ); ?>"><?php echo esc_html( $search_field['label'] ); ?></label>
57  <?php
58  }
59 
60  echo strtr( '<div id="field_{form_id}_{field_id}">{input}</div>', array(
61  '{form_id}' => $form->ID,
62  '{field_id}' => $field->ID,
64  ) );
65  ?>
66 </div>
67 <script>
68 ( function( $ ) {
69  $( 'select', '.gv-search-field-chainedselect').on( 'change', function( e ) {
70  window.gform.doAction( 'gform_input_change', e.target, <?php echo (int) $form->ID; ?>, <?php echo (int) $field->ID; ?> );
71  });
72 <?php
73  echo strtr( 'new GFChainedSelects( {form_id}, {field_id}, {hide_inactive}, "{search_layout}" );', array(
74  '{form_id}' => $form->ID,
75  '{field_id}' => $field->ID,
76  '{hide_inactive}' => (int) $hide_inactive,
77  '{search_layout}' => $gravityview_view->search_layout,
78  ) );
79 ?>
80 } )( jQuery );
81 </script>
static getInstance( $passed_post=NULL)
$hide_inactive
Choose whether to hide inactive dropdowns in the chain.
static by_id( $form, $field_id)
Get a by and Field ID.
static from_form( $form)
Construct a instance from a Gravity Forms form array.
$alignment
Prevent Chained Select Search Bar input fields from outputting styles.
if(! class_exists( 'GF_Chained_Field_Select')) if(empty( $search_field['choices'])) $form
gravityview()
The main GravityView wrapper function.
gv_empty( $value, $zero_is_empty=true, $allow_string_booleans=true)
Is the value empty?