Skip Navigation

[Resolved] Blank fild in dropdown – Code not working

This support ticket is created 2 years, 6 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 Shane 2 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2359995

I'm trying to have a default empty value for my dropdown lists, so users need to select a specific choice.

I've used the code of this tread : //toolset.com/forums/topic/blank-field-in-taxonomy-dropdown/

I've added it into the javascript form box and tried with and without 'wpcf-' but it doesn't work.

jQuery(document).ready(function($){
jQuery("select[name='wpcf-pays-provinces']").prepend('<option value="">- Sélectionnez la région -</option>');
jQuery("select[name='wpcf-pays-provinces']")[0].selectedIndex = 0;
});

Here is the code of my dropdown list

<div class="cred-label">[wpml-string context="cred-logement"]Province[/wpml-string]</div>
[cred_field field='pays-provinces' display='select' single_select='true']
</div>

Thanks 🙂

Catherine

#2360081

Shane
Supporter

Languages: English (English )

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

Hi Catherine,

Thank you for getting in touch.

You shouldn't need to use code for this. There is a default label option.

Try using this attribute default_label="Value" to your field's shortcode.

Thanks,
Shane

#2365143

Sorry for late reply!

I changed the code, but it still doens't work
[cred_field field='pays-provinces' display='select' single_select='true' default_label="Value"]

#2365227

Shane
Supporter

Languages: English (English )

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

Hi Catherine,

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.

Thanks,
Shane

#2365281

Shane
Supporter

Languages: English (English )

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

Hi Catherine,

Thank you I went ahead and looked at the issue and corrected your code.

jQuery(document).ready(function($){
jQuery("select[name='pays-provinces[]']").prepend('<option value="0">- Sélectionnez la région -</option>');

jQuery("select[name='pays-provinces[]']")[0].selectedIndex = 0;
});

The above is the correct code to set the default value as well as select it.

Thanks,
Shane

#2365323

I added the code and it worked, thanks 🙂

About the default_label="Value", any clue why it wasn't working?

#2365365

Shane
Supporter

Languages: English (English )

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

Hi Catherine,

About the default_label="Value", any clue why it wasn't working?

This was my error I initially believed this was for a view search but turns out to be for a form.

Thanks,
Shane