Skip Navigation

[Resolved] How to autofill parent custom field?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to set default option for view's dropdown select filter
Solution:
To set the default option for view's dropdown select filter you should add custom javascrip code to your view's filter section's JS box.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/how-to-autofill-parent-custom-field/#post-775983

Relevant Documentation:

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Charles 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#775629
Screen Shot 2018-05-01 at 2.16.34 PM.jpg

Hi,

I'm trying to autofill a country in my real estate search fill with following commands in View:

[wpv-control-post-relationship ancestors="city>area" url_param="wpv-relationship-filter"]
<div class="form-group col-xs-6">
[wpv-control-post-ancestor type="select" auto_fill="Singapore" ancestor_type="city"]
</div>
<div class="form-group col-xs-6">
[wpv-control-post-ancestor type="select" default_label="- Any Area/District -" ancestor_type="area"]
</div>
[/wpv-control-post-relationship]

I managed to autofill city (parent) with "Singapore" when the page loads every time. However, the area (child) field doesn't work unless I manually selects its parent, Singapore again. I tried default_label="Singapore" - won't work either.

How to enable the child to work when auto selecting the parent or am I using the wrong command to auto select?

#775811

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I think its possible by adding custom javascript and trigger the change event for your parent dropdown.

If it possible for you to send me problem URL and access details so that I can share solution with you.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#775842

This is the view that I like the default parent field, city to be "Singapore":
hidden link

Thanks.

#775983

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now. I've added following code to your view's filter's JS box:


jQuery(document).ready(function($){
  $('select[name="wpv-relationship-filter-city"] option[value="84"]').attr('selected','selected');
  $('#wpv_control_select_wpv-relationship-filter_city').trigger('change');
});

I can see the child dropdown is working fine. Could you please confirm.

#775993

Many thanks Minesh. It's working. Excellent!