Map field default location in clonable group....via AJAX?

Support Meta Box AIO Map field default location in clonable group....via AJAX?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #45722
    Andrew_VincentAndrew_Vincent
    Participant

    Hey there.

    I have a site (currently being redeveloped) that incorporates a form with a clone-able group. Each group includes a Google Map field where users input a location. Users add multiple groups (Paddocks) to be submitted.
    The client has asked that subsequent Paddocks use the previous input as the default (std) location and zoom - but I don't see how this can be achieved..?

    The form is currently online here:
    https://flexigrain.com.au/express-your-interest/expression-of-interest-vic/

    Thanks

    #45730
    PeterPeter
    Moderator

    Hello Andrew,

    I'm afraid that there isn't an option to set the default value of the next map field by the value of the previous map field.

    #45735
    Andrew_VincentAndrew_Vincent
    Participant

    Thanks. Is it possible to maybe add multiple markers to a single map?

    #45738
    Andrew_VincentAndrew_Vincent
    Participant

    Another possibility would be to add to an existing form submission post. ie map for one paddock submits; subsequent paddocks retrieve default Zoom and Location from the submission CPT Location field.

    ... does that make sense?

    #45750
    PeterPeter
    Moderator

    Hello,

    If you want to show the default value for the subfield in a cloneable group, you can follow the documentation https://docs.metabox.io/extensions/meta-box-group/#setting-default-group-values

    There isn't an option to get the value of the 1st subfield and display it as the default value of the 2nd subfield.

    It is possible to display multiple markers on a map, you need to create some custom code to do that. Here is a reference https://metabox.io/display-all-listings-on-a-map/

    #45756
    Andrew_VincentAndrew_Vincent
    Participant

    No I think you're not understanding. The user would need to input multiple markers on a map - I don't believe that's possible.

    I should theoretically be able add multiple maps to a single submission if I set the form to 'edit' => true. The newly created submission post could store the co-ordinates and set that as the default for subsequent map additions. Unfortunately the documentation on this is extremely poor so incredibly difficult to work out how to do it. https://docs.metabox.io/extensions/mb-frontend-submission/

    If I set edit to true it returns a blank page on submission. How do I set the redirect to view the newly created submission post?

    #45763
    PeterPeter
    Moderator

    Hello,

    The user would need to input multiple markers on a map - I don't believe that's possible.

    There are two cases:
    - When adding the map input value: yes, it isn't possible to add more markers on a map.
    - When outputting the map value: it is possible with custom code.

    How do I set the redirect to view the newly created submission post?

    If the attribute edit="true", after submitting the frontend form, you can edit the post directly. That means seeing the same frontend form with submitted data. If it doesn't work, can you share the frontend shortcode?

    #45806
    Andrew_VincentAndrew_Vincent
    Participant

    My code looks like this:

    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
    
    	$meta_boxes[] = array (
    		'title' => 'Submit Paddock',
    		'id' => 'submit_paddock_form_vic',
            'post_types' => 'eoi',
            'edit' => true,
            'validation'    =>  [
                'rules' =>  [
                                'phone' => [
                                            'required' => true,
                                            ],
                                'full_name' => [
                                            'required' => true,
                                            ],
                                'email' => [
                                            'required' => true,
                                            ],
                            ]
    
            ],
    		'fields' => [
                [
                    'id'    =>  'recipients',
                    'type'  =>  'hidden',
                    'std'  => '[email protected],[email protected]',
                    'std'  => '[email protected]',
                ],
                [
                    'name'  =>  'Full Name',
                    'id'    =>  'full_name',
                    'type'  => 'text',
                ],
                [
                    'name'  =>  'Contact Phone',
                    'id'    =>  'phone',
                    'type'  => 'text',
                ],
                [
                    'name'  =>  'Contact Email',
                    'id'    =>  'email',
                    'type'  => 'text',
                ],
                [
                    'name'  =>  'NGR',
                    'id'    =>  'ngr',
                    'type'  => 'text',
                ],
                [
                    // 'name'   => 'Add a paddock', 
                    'id'     => 'paddock_group',
                    'type'   => 'group',
                    'clone'  => true,
                    'collapsible' => true,          // Column size (1-12)
                    'class' => 'paddock_picker',
                    'group_title' => 'Paddock {#}',
                    'group_title' => ['field' => 'paddock_name'],
                    'add_button' => '+ Add a paddock',
                    'fields' => [
    
                                    [
                                        'name'  =>  'Paddock Location',
                                        'id'    =>  'paddock_location',
                                        'desc'  =>  'Select the satellite view then drag the marker whilst zooming in to locate your paddock.',
                                        'type'  => 'map',
                                        'api_key'   => 'AIzaSyBUtodUtVKW1VJa9Gmzz2-VuQuwd7A7GLQ',
                                        'std'   => '-35.3453808,143.5625836,7',
                                        'clone_default' => true,
                                        'js_options' => [
                                            'mapTypeId'   => 'SATELLITE',
                                        ],
                                    ],
                                    [
                                        'name'  =>  'Paddock Name',
                                        'id'    =>  'paddock_name',
                                        'type'  => 'text',
                                    ],
                                    [
                                        'name'  =>  'Crop Type',
                                        'id'    =>  'crop_type',
                                        'type'  => 'select',
                                        'options'   => [
                                            'wheat'     => 'Wheat',
                                            'barley'    => 'Barley',
                                            'feed_corn'    => 'Corn',
                                        ],
                                        'placeholder'   => 'Select a crop',
                                    ],
                                    [
                                        'name'  =>  'Variety',
                                        'id'    =>  'variety',
                                        'type'  => 'text',
                                    ],
                                    [
                                        'name'  =>  'Plantable Hectares',
                                        'id'    =>  'plantable_hectares',
                                        'type'  => 'text',
                                    ],
                                    [
                                        'name'  =>  'Delivery Location',
                                        'id'    =>  'delivery_location',
                                        'type'  => 'text',
                                    ],
                    ],
                ],
            ]
        );
        
    	return $meta_boxes;
    });
    #45819
    Andrew_VincentAndrew_Vincent
    Participant

    Can you please confirm that I placed 'edit' => true in the right place?

    #45823
    PeterPeter
    Moderator

    Hello,

    No, it's the wrong place.

    if I set the form to 'edit' => true

    you are talking about the frontend form, so you need to add the attribute edit to the form shortcode. But it is added to the meta box settings.

    Please read the documentation carefully to use the shortcode attributes:
    https://docs.metabox.io/extensions/mb-frontend-submission/#adding-the-submission-form

    [mb_frontend_form id="field-group-id" post_fields="title,content" edit="true"]

    #45870
    Andrew_VincentAndrew_Vincent
    Participant

    Thanks - that makes sense.

    It looks like the CPT thats created on submit can't be viewed. I can view it in the back end but there is no 'View EoI" button. Is that necessary? or is the cpt content somehow appended to the confirmation message?

    Should the redirect on submit be directed to the cpt URL?

    #45871
    Andrew_VincentAndrew_Vincent
    Participant

    ^^ Just to clarify my comment above... I'm not trying to edit the CPT in the back-end, but have noticed that its not possible to view the CPT - i'm guessing because of the way the CPT is defined when created by the front-end-form..? And if it's not viewable, I don't see how it can be editable.

    Does that make sense?

    #45879
    PeterPeter
    Moderator

    Hello,

    If you want to view the submitted post from the frontend form, you can use the frontend dashboard. Then click on the post title to view the post.
    Following the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#user-dashboard

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