Support Forum
Support › Meta Box Geolocation › Only auto populate neighborhood field if not emptyResolved
I have a field for the neighborhood. Sometimes google will return a neighborhood value for an address and this will autopopulate because the field ID auto binds:
array(
'type' => 'text',
'name' => __('Neighborhood', 'psych-info'),
'id' => 'neighborhood',
),
The issue is when google does not return a neighborhood value, then this field is cleared of any existing value. I know I can change the ID to prevent the auto-binding, but maybe this could be improved?
I can think of a couple of workarounds:
array(
'type' => 'text',
'name' => __('Neighborhood', 'psych-info'),
'id' => 'neighborhood',
'binding' => 'neighborhood',
'bind_if_empty' => false, //default true
),
bind_if_empty might also accept a secondary field to bind if the first field is empty:
'binding' => 'neighborhood',
'bind_if_empty' => 'sublocality'
I am happy to extend the plugin. If so, is there a private repo I can submit a pull request to?
P.S. There is a typo in the Features section on the extension's page:
Auto popular all location fields when user enter an address
should read:
Auto populate all location fields...
Update: I have added a working bind_if_empty. Please me know how best to submit a pull request.
Two weeks and crickets... The following changes would need to be made to include the
'bind_if_empty' => false, //default true
idea described above.
File: js/mp-geo.js
Line: 85
var $this = $( this ),
dataBinding = $this.data( 'binding' ),
dataBindEmpty = $this.data( 'bind_if_empty' ),
addressField = $this.data( 'address_field' ),
fieldValue = that.getFieldData( dataBinding, place );
File: inc/class-meta-box-geolocation.php
Line: 97
$binding = isset( $field['binding'] ) ? $field['binding'] : $this->guessBindingField( $field['id'] );
$bind_if_empty = isset( $field['bind_if_empty'] ) ? $field['bind_if_empty'] : 1;
$address_field = isset( $field['address_field'] ) ? $field['address_field'] : '';
if ( $binding ) {
$begin .= '<script type="html/template" class="rwmb-geo-binding" data-binding="' . esc_attr( $binding )
. '" data-bind_if_empty="' . esc_attr( $bind_if_empty )
. '" data-address_field="' . esc_attr( $address_field )
...
Would be fantastically 2019 if there was a magical way to submit a pull request.
Thanks for your help!
I've sent an invitation to you on Bitbucket, so you can have access to the repo and open a PR!
Cheers!
Thank you. PR has been submitted.
Issue may be marked as resolved.