Frontend Submission - Google Maps - Custom Binding

Support MB Frontend Submission Frontend Submission - Google Maps - Custom Binding

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #45746
    CodogCodog
    Participant

    Hi there,
    I have a frontend submission form that contains a Google Map and address field that uses the Geocoding API for autocomplete. All works as expected!

    However, I don't seem to be able to get the "Custom Binding" working as documented here

    Here is my code with an attempt to bind the 'City' & 'Country' to a hidden custom field:

    			
      // Map field.
      [
      'id'            => 'location_map',
      'type'          => 'map',
      'api_key'       => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      'std'           => '51.5074,-0.1278,15',
      'address_field' => 'location_address',
      ],
      // Address field.
      [
      'id'   => 'location_address',
      'name' => __( 'Address', 'text-domain' ),
      'type' => 'text',
      'placeholder'   => 'Enter address...',
      'desc'     => __( 'Enter the complete address.', 'text-domain' ),
      'required' => true,
      ],
      // Hidden field to store the city and country
      [
      'id'   => 'city_country',
      'type' => 'hidden',
      'binding' => 'city + " " + country',
      'std'  => 'null',
      ],
    

    Expected result: Autocomplete - City and Country values to be added to hidden field.
    Actual result: Returns nothing?

    I have also tried this with a plain text field and the result is the same?

    What am I missing?

    Thanks in advance 🙂

    #45752
    PeterPeter
    Moderator

    Hello,

    Do you add the setting geo to the field group settings? Please follow the documentation https://docs.metabox.io/extensions/meta-box-geolocation/#field-group-settings

    #45753
    CodogCodog
    Participant

    Hi Peter, thanks for the response. Yeah this was the bit I was unclear about? I assume you mean adding this:

    
    'geo' => [
        'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
    ],
    

    To some field group? Do you mean I need to wrap my "Map Field, Address Field , Hidden field" in a "Field Group and add the above? Not clear to me?

    As I am strictly doing this with code I would be grateful if you could show me a simple example?

    #45761
    PeterPeter
    Moderator

    Hello,

    If you use the code to register the meta box (field group in the builder UI), you need to add geo to the meta box settings. For example:

    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        $meta_boxes[] = [
            'title'      => 'Event details',
            'post_types' => 'event',
            'geo' => [
                'api_key' => 'YOUR API KEY',
            ],
            'fields'     => [
                ...
            ],
        ];
    
        return $meta_boxes;
    } );

    https://docs.metabox.io/creating-fields-with-code/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.