Good morning,
I need to put -not set as first choice in a form, in a category dropdown
Could you help me?
Raja Mohammed
Supporter
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
Hello there,
The taxonomy field are expected to have a default category name selected and thats the reason the taxonomy dropdown does not have a not set field. The only way for you to achieve it would be a DIY solution where you add a little custom jQuery to insert an empty option element for the select field when the page loads. I tried the below snippet in my test site which seems to work. You might need to alter the code based on your requirements.
jQuery('select[name="category[]"]').prepend(jQuery("<option></option>").attr( { "value":'', "selected" : 'selected'} ).text('--Not Set--'));
Regards
Raja
Thanks Raja,
Where i can put this code?
Raja Mohammed
Supporter
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
You can use that in the form JS editor section inside the form editor
Do I have to add anything else to the code? Javascript is not my strong point
I add this because is an taxonomy
jQuery('select[name="taxonomy[]"]').prepend(jQuery("<option></option>").attr( { "value":'', "selected" : 'selected'} ).text('--Not Set--'));
but, doesnt work.
Raja Mohammed
Supporter
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
Please share temporary access to the site let me check this quick, I have enabled private fields to securely share the details.
Regards
Raja
Raja Mohammed
Supporter
Idiomas:
Inglés (English )
Zona horaria:
Asia/Kolkata (GMT+05:30)
The field name is zonas[], i have adjusted the JS snippet on your site as
jQuery('select[name="zonas[]"]').prepend(jQuery("<option></option>").attr( { "value":''} ).text('--Not Set--'));
Please note the JS snippet will only add the first entry as Not Set, You might have to take it from here and add your own customization to handle them as per your needs.
Thanks Raja for your help,
Is it posible that not set appear by default selection?
Now is other item, i attach you an image.
Nigel
Supporter
Idiomas:
Inglés (English )
Español (Español )
Zona horaria:
Europe/London (GMT+00:00)
Rafa is off today, so I took a look.
The new option needs the selected attribute, and I've added it with the document ready event, so the updated code which is working is:
jQuery( document ).ready( function(){
jQuery('select[name="zonas[]"]').prepend('<option value="" selected>--Elegir--</option>');
});
My issue is resolved now. Thank you!