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
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
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"]
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
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
I added the code and it worked, thanks 🙂
About the default_label="Value", any clue why it wasn't working?
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