Skip Navigation

[Resolved] drop-down list of taxonomies, first choice

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

Problem:
How to set default option for taxonomy dropdown select
Solution:
You need to add custom jQuery or Javascript code to your CRED form's JS box to set default option for taxonomy dropdown select.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/drop-down-list-of-taxonomies-first-choice/#post-613116

Relevant Documentation:

This support ticket is created 6 years, 10 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.

Our next available supporter will start replying to tickets in about 1.27 hours from now. Thank you for your understanding.

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 20 replies, has 2 voices.

Last updated by massimoS527 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#610774

I have a drop-down list of taxonomies, I created a taxonomy with a name "-choose-" to get a default label and invite the user to make the choice?
how can I make taxonomy "-choose-" is not seen as a taxonomy.
is there a trick?

#610940

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know where you are displaying the taxonomy filed as select drop-down - is it using CRED form?

Have you created "-choose-" option as taxonomy term?

#611074

I would like to know where you are displaying the taxonomy filed as select drop-down - is it using CRED form?
Yes CRED form

Have you created "-choose-" option as taxonomy term?
Yes

I created you a user for 24 hours
user: staff
pass: toolset

log in to the site and click on "add creature" at the end of the form you find the three drop-down fields
(they are taxonomies)

#611270

Minesh
Supporter

Languages: English (English )

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

Well - you should not add default option "-choose-" as taxonomy term.

Rather you can use some javascript/jQuery code to add default option to your taxonomy select box.

For example - Try to add following code to your CRED form's JS box and adjust the select box name as described:

jQuery("select[name='YOUR-SELECT-NAME']").prepend('<option value="">- choose-</option>');
jQuery("select[name='YOUR-SELECT-NAME']")[0].selectedIndex = 0;

Where:
- Replace 'YOUR-SELECT-NAME' with your original select name

#611421

Hi Minesh,
I have three drop-down lists of taxonomies, here is the code of the CRED module

<div class="form-group">
		<label>[wpml-string context='cred-form-aggiungi creatura originale-348' name='creature-sesso']sesso[/wpml-string]</label>
		[cred_field field='creatura-sesso' display='select' single_select='true' output='bootstrap']
		</div>

	<div class="form-group">
		<label>[wpml-string context='cred-form-aggiungi creatura originale-348' name='creature-specie']specie[/wpml-string]</label>
		[cred_field field='creatura-specie' display='select' single_select='true' output='bootstrap']
		</div>

	<div class="form-group">
		<label>[wpml-string context='cred-form-aggiungi creatura originale-348' name='creature-vita-assieme']siamo stati assieme per...[/wpml-string]</label>
		[cred_field field='creatura-vita-assieme' display='select' single_select='true' output='bootstrap']
		</div>

I canceled the first taxonomy -choose- I entered your code in the "JS editor" section of the CRED module, but there are no changes

#611422

Minesh
Supporter

Languages: English (English )

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

Ahh - could you please try following code:

jQuery(document).ready(function($){

jQuery("select[name='creatura-sesso']").prepend('<option value="0">- choose-</option>');
jQuery("select[name='creatura-sesso']")[0].selectedIndex = 0;


jQuery("select[name='creatura-specie']").prepend('<option value="0">- choose-</option>');
jQuery("select[name='creatura-specie']")[0].selectedIndex = 0;

jQuery("select[name='creatura-sesso']").prepend('<option value="0">- choose-</option>');
jQuery("select[name='creatura-vita-assieme']")[0].selectedIndex = 0;

});
#611443
Screenshot-2018-1-31 add-creatures – Riplove.png

nothing, the first item of the drop down menu does not change

#611445

Minesh
Supporter

Languages: English (English )

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

Could you please share problem URL?

*** 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.

#611456

I'm sorry I do not want to upset all my work.
I created you a user for 24 hours:

hidden link

access details removed

the problem can be found here: hidden link
at the end you will find the 3 drop-down menus

#611689

Minesh
Supporter

Languages: English (English )

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

Thank you for sharing access details but I could not able to access anything using this account. Could you please grant full access rights to the user so that I can access CRED forms etc..etc .

*** 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.

#612629

Minesh
Supporter

Languages: English (English )

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

Thank you for sharing access details but unfortunately the shared access details are not working.

Could you please check access details once and send me working access details.

#613116

Minesh
Supporter

Languages: English (English )

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

Could you please check now. I can see now it's working fine.

I've added the following code to your CRED form's JS box:

jQuery(document).ready(function($){
 
jQuery("select[name='creatura-sesso[]']").prepend('<option value="0">-choose-</option>');
jQuery("select[name='creatura-sesso[]']")[0].selectedIndex = 0;
 
 
jQuery("select[name='creatura-specie[]']").prepend('<option value="0">-choose-</option>');
jQuery("select[name='creatura-specie[]']")[0].selectedIndex = 0;
 
jQuery("select[name='creatura-vita-assieme[]']").prepend('<option value="0">-choose-</option>');
jQuery("select[name='creatura-vita-assieme[]']")[0].selectedIndex = 0;
 
});
#613165

very good, it works !!!
How can I make the choice of taxonomies an obligatory field?

this is the code I use in the CRED module

<div class="form-group">
		<label>[wpml-string context='cred-form-aggiungi creatura originale-348' name='creature-sesso']sesso[/wpml-string]</label>
		[cred_field field='creatura-sesso' display='select' single_select='true' output='bootstrap']
		</div>

thanks

#613176

Minesh
Supporter

Languages: English (English )

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

You can validate your CRED form using CRED API hook: cred_save_data

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#613179

I'm not able to use hooks