Only auto populate neighborhood field if not empty
Support › MB Geolocation › Only auto populate neighborhood field if not emptyResolved
- This topic has 4 replies, 2 voices, and was last updated 6 years, 2 months ago by
pluginoven.
-
AuthorPosts
-
January 30, 2019 at 5:04 PM #13165
pluginoven
ParticipantI 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:
- add a fill bind_if_empty flag in the plugin:
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'
- Allow the binding to be filtered by a function
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...January 30, 2019 at 6:42 PM #13167pluginoven
ParticipantUpdate: I have added a working bind_if_empty. Please me know how best to submit a pull request.
February 12, 2019 at 9:36 PM #13277pluginoven
ParticipantTwo 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: 85var $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.
February 13, 2019 at 11:59 AM #13293Anh Tran
KeymasterThanks 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!
February 13, 2019 at 10:27 PM #13310pluginoven
ParticipantThank you. PR has been submitted.
Issue may be marked as resolved. - add a fill bind_if_empty flag in the plugin:
-
AuthorPosts
- You must be logged in to reply to this topic.