Map field default location in clonable group....via AJAX?
Support › Meta Box AIO › Map field default location in clonable group....via AJAX?
- This topic has 12 replies, 2 voices, and was last updated 9 months, 2 weeks ago by
Peter.
-
AuthorPosts
-
June 26, 2024 at 9:35 AM #45722
Andrew_Vincent
ParticipantHey 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
June 26, 2024 at 10:40 PM #45730Peter
ModeratorHello 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.
June 27, 2024 at 7:20 AM #45735Andrew_Vincent
ParticipantThanks. Is it possible to maybe add multiple markers to a single map?
June 27, 2024 at 8:52 AM #45738Andrew_Vincent
ParticipantAnother 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?
June 27, 2024 at 9:44 PM #45750Peter
ModeratorHello,
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/
June 28, 2024 at 8:15 AM #45756Andrew_Vincent
ParticipantNo 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?
June 28, 2024 at 10:19 PM #45763Peter
ModeratorHello,
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?July 2, 2024 at 11:23 AM #45806Andrew_Vincent
ParticipantMy 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; });
July 3, 2024 at 6:38 AM #45819Andrew_Vincent
ParticipantCan you please confirm that I placed 'edit' => true in the right place?
July 3, 2024 at 8:41 PM #45823Peter
ModeratorHello,
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"]
July 10, 2024 at 12:32 PM #45870Andrew_Vincent
ParticipantThanks - 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?
July 10, 2024 at 12:43 PM #45871Andrew_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?
July 10, 2024 at 8:39 PM #45879Peter
ModeratorHello,
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 -
AuthorPosts
- You must be logged in to reply to this topic.