Saltar navegación

[Resuelto] not set in dropdown category

This support ticket is created hace 4 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.

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 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Etiquetado: 

Este tema contiene 10 respuestas, tiene 3 mensajes.

Última actualización por avansisI-2 hace 4 años, 2 meses.

Asistido por: Raja Mohammed.

Autor
Mensajes
#1847215

Good morning,

I need to put -not set as first choice in a form, in a category dropdown

Could you help me?

#1847455

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

#1847529

Thanks Raja,

Where i can put this code?

#1847541

Raja Mohammed
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Screenshot 2020-11-17 at 8.25.37 PM.jpg

You can use that in the form JS editor section inside the form editor

#1847599

Do I have to add anything else to the code? Javascript is not my strong point

#1847669

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.

#1848135

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

#1849373

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.

#1851349
Captura de pantalla 2020-11-20 a las 21.41.12.png

Thanks Raja for your help,

Is it posible that not set appear by default selection?

Now is other item, i attach you an image.

#1853369

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>');
});
#1853419

My issue is resolved now. Thank you!