Skip to content

Commit 082c866

Browse files
committed
gpadvs-enable-add-new-option.php: Fixed HTML entity display in no results text and added new hide option.
1 parent b7e9bf7 commit 082c866

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct( $args = array() ) {
2525
'form_id' => false,
2626
'field_id' => false,
2727
'insert_new_option' => false,
28+
'hide_no_results_text' => false,
2829
) );
2930

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

8586
settings.create = true;
8687

88+
// Hide "No results found" message if enabled
89+
if ( args.hideNoResultsText ) {
90+
if ( ! settings.render ) {
91+
settings.render = {};
92+
}
93+
settings.render.no_results = null;
94+
}
95+
8796
/**
8897
* Uncomment the below code to customize the display of the "Add New" option.
8998
*/
@@ -113,6 +122,7 @@ public function add_init_script( $form ) {
113122
$args = array(
114123
'formId' => $this->_args['form_id'],
115124
'fieldId' => $this->_args['field_id'],
125+
'hideNoResultsText' => $this->_args['hide_no_results_text'],
116126
);
117127

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

307317
if ( is_array( $choices ) && rgar( $choices[0], 'gppaErrorChoice' ) == 'no_choices' ) {
308-
unset( $choices[0]['gppaErrorChoice'] );
318+
// If hide_no_results_text is enabled, remove the choice entirely
319+
if ( $this->_args['hide_no_results_text'] ) {
320+
array_shift( $choices );
321+
} else {
322+
unset( $choices[0]['gppaErrorChoice'] );
323+
324+
if ( isset( $choices[0]['text'] ) ) {
325+
$choices[0]['text'] = html_entity_decode( $choices[0]['text'] );
326+
}
327+
}
309328
}
310329
return $choices;
311330
}
@@ -316,4 +335,5 @@ public function enable_new_choice_for_gppa_empty( $choices, $field, $objects ) {
316335
new GPASVS_Enable_Add_New_Option(array(
317336
'form_id' => 123,
318337
// 'field_id' => 4,
338+
// 'hide_no_results_text' => true,
319339
));

0 commit comments

Comments
 (0)