Skip Navigation

[Resolved] Radio (or) Checkbox Field pre-selected in a Search

This support ticket is created 4 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Jaime 4 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1512949

Tell us what you are trying to do?
I need to have a field (as radio buttons or checkbox) with an option preselected. But I can't achieve to do it.

Is there any documentation that you are following?
Yes, I tried this two topics, but none of them working for me.
https://toolset.com/forums/topic/pre-fill-value-for-checkboxes-select-lists-and-radio-buttons/
https://toolset.com/forums/topic/pre-select-radio-button-in-cred-post-form-based-on-user-field/

Is there a similar example that we can see?

What is the link to your site?
I'm working on a test site.
hidden link
Here yo can see the checkbox which I would like to pre select.

Thanks!

#1513227

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jaime,

Thank you for getting in touch.

For radio buttons you will need the code below.

Add the code below and let me know if it helps.
jQuery("#categoria-buscador-empresas-buscador").attr('checked', 'checked');

Thanks,
Shane

#1514323

Hi Shane.
Sorry, but it didn't worked.
I tried this before, but noting really happened.

This radio buttons are a taxonomie (not sure if this change anything) but not neccesary the field needs to be a taxonomie, actually, and if it's easier I can try to solve my problem changing this taxonomie to a field.

(For your information. What I'm trying to achieve is two searchs in separate by tabs in the same page. So, this pre-checked field will be display none by CSS and it helps me to show different results in the two search forms. I know it's a little tricky, but it's the best workaround to solve my problem. So, that's why it's not mandatory to have the taxonomie pre-selected).

Thanks a lot Shane.

#1514913

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jaime,

To get this clear you want to have 2 different results from the same view but in 2 different tabs on the same page ?

If so then this actually isn't possible to achieve be cause the search filters are tied to the view itself.

Thanks,
Shane

#1514919

Well, not exactly.
I have two identical searchs, separate with a tab . But they are not the same. I mean, they have differents ID's and names.
I thought this could be the problem, so I deleted one of my searchs from the tabs, but the result is the same. The pre-selected radio options didn't work with one single search.

You can see it in action with your code added and no other search working in the same page
hidden link

As you can see no pre-selected radio charges.

Any other options?
🙂

#1515131

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jaime,

The issue here I see is that the search form must be submitted.

So the full code would be something like

jQuery( document ).ready(function() {
jQuery("#categoria-buscador-empresas-buscador").attr('checked', 'checked');
   jQuery("form[name ='wpv-filter-7214']") .submit();
});

The problem we run into now is that the form won't submit using AJAX since we are using jQuery to submit the form and not an actual click.

This now should work with selecting the option and submitting the form but only with a full page refresh.

Thanks,
Shane

#1518047

My issue is resolved now. Thank you Shane!
I solved it with a "select option" and "insert values manually " selecting the field I need in each search form.
Something like this
1) This one for Empresas
[wpv-control-postmeta field="wpcf-tipo-de-empresa" source="custom" url_param="wpv-wpcf-tipo-de-empresa" values="Empresa" display_values="Empresa"]

2) Profesionales
[wpv-control-postmeta field="wpcf-tipo-de-empresa" source="custom" url_param="wpv-wpcf-tipo-de-empresa" values="Profesional" display_values="Profesional"]

With this solution I can sort the results in two different search forms separate with a tab based on this field.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.