diff --git a/gp-advanced-select/gpadvs-enable-add-new-option.php b/gp-advanced-select/gpadvs-enable-add-new-option.php index a20e06c7c..cd793bcae 100644 --- a/gp-advanced-select/gpadvs-enable-add-new-option.php +++ b/gp-advanced-select/gpadvs-enable-add-new-option.php @@ -51,6 +51,9 @@ public function init() { add_filter( 'gform_pre_render', array( $this, 'add_new_option_to_choices' ), 10, 1 ); add_action( 'gform_after_submission', array( $this, 'create_new_option' ), 10, 2 ); + + add_filter( 'gppa_input_choices', array( $this, 'enable_new_choice_for_gppa_empty' ), 10, 3 ); + } public function load_form_script( $form, $is_ajax_enabled ) { @@ -293,6 +296,19 @@ public function create_new_option( $entry, $form ) { gform_update_meta( $entry['id'], 'gppa_choices', $gppa_choice_labels, $form['id'] ); } } + + public function enable_new_choice_for_gppa_empty( $choices, $field, $objects ) { + + $form = GFAPI::get_form( $field->formId ); + if ( ! $this->is_applicable_form( $form ) || ! $this->is_applicable_field( $field ) ) { + return $choices; + } + + if ( is_array( $choices ) && rgar( $choices[0], 'gppaErrorChoice' ) == 'no_choices' ) { + unset( $choices[0]['gppaErrorChoice'] ); + } + return $choices; + } } # Configuration