Skip Navigation

[Resuelto] CRED: blank/empty default value for taxonomy select field

This support ticket is created hace 3 años, 2 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 respuestas, has 2 mensajes.

Last updated by Waqar hace 3 años, 2 meses.

Assisted by: Waqar.

Autor
Mensajes
#1919769

I found this from 8 years ago: https://toolset.com/forums/topic/cred-blank-default-value-for-taxonomy-select-field-validation/

I want to have a taxonomy field with no default value. Currently, my select dropdown defaults to the first option.

I have tried this, but it doesn't work:

[cred_field field='country' force_type='taxonomy' output='bootstrap' display='select' single_select='true' default_label=""]

How do I have an empty value by default for the dropdown?

#1919993

Waqar
Supporter

Languages: Inglés (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

Currently, there is no built-in parameter, to insert a default empty option in the taxonomy select field in the form.

We have an internal ticket to introduce this and I've added your voice to this feature request as well.

For now, a workaround can be to include some custom script in your form's "JS editor". For example:


jQuery(document).ready(function($) {
	jQuery("select[name='country[]']").prepend('<option value="">- Select -</option>');
	jQuery("select[name='country[]']")[0].selectedIndex = 0;
});

Note: Please replace "country" with your actual taxonomy's slug.

regards,
Waqar

#1922499

Thanks.

How do I force the user to make a selection?

required='true'

doesn't exactly work, I guess because it sees - Select - as a valid selection?

#1922801

Waqar
Supporter

Languages: Inglés (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

I've tested this script on my website and it works to make the select field required:


jQuery(document).ready(function($) {
	jQuery("select[name='category[]']").prepend('<option value="">- Select -</option>');
	jQuery("select[name='category[]']")[0].selectedIndex = 0;
	jQuery("select[name='category[]']").attr("required","");
});

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