Skip to content
Merged
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
16 changes: 16 additions & 0 deletions gp-advanced-select/gpadvs-enable-add-new-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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
Expand Down
Loading