Skip to content

Commit a91f38a

Browse files
authored
Fix location field bug on new contact screen (#2687)
Locations field was showing a plus icon with no empty field to enter a location. When selecting a location, it would just show a spinner because it sent an API request that was failing.
1 parent 8564bf1 commit a91f38a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

dt-core/global-functions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr
642642
}
643643

644644
if ( $is_legacy ) {
645+
$is_empty_post = count( array_keys( $post ) ) <= 1; // if this is a new post, it only has a post_type key
645646
?>
646647
<div class="section-subheader">
647648
<?php dt_render_field_icon( $fields[$field_key] );
@@ -692,7 +693,7 @@ class="add-link__option"
692693
</div>
693694

694695
<?php endif; ?>
695-
<?php if ( ( $field_type === 'location' || 'location_meta' === $field_type ) && DT_Mapbox_API::get_key() && ! empty( $post ) ) : ?>
696+
<?php if ( ( $field_type === 'location' || 'location_meta' === $field_type ) && DT_Mapbox_API::get_key() && !$is_empty_post ) : ?>
696697
<button data-list-class="<?php echo esc_html( $field_key ) ?>" class="add-button" id="new-mapbox-search" type="button" <?php echo esc_html( $disabled ); ?>>
697698
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/small-add.svg' ) ?>"/>
698699
</button>
@@ -787,7 +788,7 @@ class="text-input" value="<?php echo esc_html( $post[$field_key] ?? '' ) ?>" <?p
787788
</div>
788789
</div>
789790
<?php elseif ( $field_type === 'location_meta' ) : ?>
790-
<?php if ( DT_Mapbox_API::get_key() && empty( $post ) ) : // test if Mapbox key is present ?>
791+
<?php if ( DT_Mapbox_API::get_key() && $is_empty_post ) : // test if Mapbox key is present ?>
791792
<div id="mapbox-autocomplete" class="mapbox-autocomplete input-group" data-autosubmit="false">
792793
<input id="mapbox-search" type="text" class="input-group-field" name="mapbox_search" placeholder="Search Location" autocomplete="off" dir="auto" <?php echo esc_html( $disabled ); ?>/>
793794
<div class="input-group-button">

0 commit comments

Comments
 (0)