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
22 changes: 21 additions & 1 deletion gp-advanced-select/gpadvs-enable-add-new-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct( $args = array() ) {
'form_id' => false,
'field_id' => false,
'insert_new_option' => false,
'hide_no_results_text' => false,
) );

// do version check in the init to make sure if GF is going to be loaded, it is already loaded
Expand Down Expand Up @@ -84,6 +85,14 @@ public function output_script() {

settings.create = true;

// Hide "No results found" message if enabled
if ( args.hideNoResultsText ) {
if ( ! settings.render ) {
settings.render = {};
}
settings.render.no_results = null;
}

/**
* Uncomment the below code to customize the display of the "Add New" option.
*/
Expand Down Expand Up @@ -113,6 +122,7 @@ public function add_init_script( $form ) {
$args = array(
'formId' => $this->_args['form_id'],
'fieldId' => $this->_args['field_id'],
'hideNoResultsText' => $this->_args['hide_no_results_text'],
);

$script = 'new GPADVSEnableAddNewOption( ' . json_encode( $args ) . ' );';
Expand Down Expand Up @@ -305,7 +315,16 @@ public function enable_new_choice_for_gppa_empty( $choices, $field, $objects ) {
}

if ( is_array( $choices ) && rgar( $choices[0], 'gppaErrorChoice' ) == 'no_choices' ) {
unset( $choices[0]['gppaErrorChoice'] );
// If hide_no_results_text is enabled, remove the choice entirely
if ( $this->_args['hide_no_results_text'] ) {
array_shift( $choices );
} else {
unset( $choices[0]['gppaErrorChoice'] );

if ( isset( $choices[0]['text'] ) ) {
$choices[0]['text'] = html_entity_decode( $choices[0]['text'] );
}
}
}
return $choices;
}
Expand All @@ -316,4 +335,5 @@ public function enable_new_choice_for_gppa_empty( $choices, $field, $objects ) {
new GPASVS_Enable_Add_New_Option(array(
'form_id' => 123,
// 'field_id' => 4,
// 'hide_no_results_text' => true,
));