Skip to content

Commit 734a1a5

Browse files
committed
gpadvs-enable-add-new-option.php: Added new choice option for GPPA No Choice scenario.
1 parent 278e693 commit 734a1a5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gp-advanced-select/gpadvs-enable-add-new-option.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function init() {
5151
add_filter( 'gform_pre_render', array( $this, 'add_new_option_to_choices' ), 10, 1 );
5252

5353
add_action( 'gform_after_submission', array( $this, 'create_new_option' ), 10, 2 );
54+
55+
add_filter( 'gppa_input_choices', array( $this, 'enable_new_choice_for_gppa_empty' ), 10, 3 );
56+
5457
}
5558

5659
public function load_form_script( $form, $is_ajax_enabled ) {
@@ -293,6 +296,19 @@ public function create_new_option( $entry, $form ) {
293296
gform_update_meta( $entry['id'], 'gppa_choices', $gppa_choice_labels, $form['id'] );
294297
}
295298
}
299+
300+
public function enable_new_choice_for_gppa_empty( $choices, $field, $objects ) {
301+
302+
$form = GFAPI::get_form( $field->formId );
303+
if ( ! $this->is_applicable_form( $form ) || ! $this->is_applicable_field( $field ) ) {
304+
return $choices;
305+
}
306+
307+
if ( is_array( $choices ) && rgar( $choices[0], 'gppaErrorChoice' ) == 'no_choices' ) {
308+
unset( $choices[0]['gppaErrorChoice'] );
309+
}
310+
return $choices;
311+
}
296312
}
297313

298314
# Configuration

0 commit comments

Comments
 (0)