Skip to content

Commit

Permalink
Added "No results found" for Map/OSM fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rilwis committed Jul 18, 2018
1 parent 7f47d26 commit 2549981
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions inc/fields/map.php
Expand Up @@ -42,6 +42,9 @@ public static function admin_enqueue_scripts() {
'jquery-ui-autocomplete',
'google-maps',
), RWMB_VER, true );
self::localize_script( 'rwmb-map', 'RWMB_Map', array(
'no_results_string' => __( 'No results found', 'meta-box' ),
) );
}

/**
Expand Down
3 changes: 3 additions & 0 deletions inc/fields/osm.php
Expand Up @@ -20,6 +20,9 @@ public static function admin_enqueue_scripts() {

wp_enqueue_style( 'rwmb-osm', RWMB_CSS_URL . 'osm.css', array( 'leaflet' ), RWMB_VER );
wp_enqueue_script( 'rwmb-osm', RWMB_JS_URL . 'osm.js', array( 'jquery', 'leaflet' ), RWMB_VER, true );
self::localize_script( 'rwmb-osm', 'RWMB_Osm', array(
'no_results_string' => __( 'No results found', 'meta-box' ),
) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/meta-box.php
Expand Up @@ -88,7 +88,7 @@ public function register_fields() {
*
* @return bool
*/
protected function is_shown() {
public function is_shown() {
$show = apply_filters( 'rwmb_show', true, $this->meta_box );

return apply_filters( "rwmb_show_{$this->id}", $show, $this->meta_box );
Expand Down
9 changes: 8 additions & 1 deletion js/map.js
Expand Up @@ -144,7 +144,14 @@
'region': that.$canvas.data( 'region' )
};
geocoder.geocode( options, function ( results ) {
response( $.map( results, function ( item ) {
if ( ! results.length ) {
response( [ {
value: '',
label: RWMB_Map.no_results_string
} ] );
return;
}
response( results.map( function ( item ) {
return {
label: item.formatted_address,
value: item.formatted_address,
Expand Down
11 changes: 9 additions & 2 deletions js/osm.js
Expand Up @@ -138,8 +138,15 @@
q: request.term,
countrycodes: that.$canvas.data( 'region' ),
"accept-language": that.$canvas.data( 'language' )
}, function( result ) {
response( result.map( function ( item ) {
}, function( results ) {
if ( ! results.length ) {
response( [ {
value: '',
label: RWMB_Osm.no_results_string
} ] );
return;
}
response( results.map( function ( item ) {
return {
label: item.display_name,
value: item.display_name,
Expand Down

0 comments on commit 2549981

Please sign in to comment.