Skip Navigation

[Resuelto] Make Taxonomy Optional When in a Select Drop-Down

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to make a single select taxonomy field optional in my CRED form by inserting a placeholder option before the term options.

Solution: There's not an option to do this in the GUI, but you could use some JavaScript to insert the placeholder option programmatically. Another ticket I worked on recently discussed this approach in some detail:
https://toolset.com/forums/topic/cred-module-edit-post-choice-taxonomy-does-not-work/
This ticket also includes some backend validation messages that you may or may not want to include. Let me know if you have questions about this approach.

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

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por Christian Cox hace 6 años, 7 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#758506

Is it possible to make it optional for the user to select a taxonomy item by adding a blank line or a "--- not set ---" option at the top of the drop-down list, same as how you would use a select_text attribute for other select fields? Currently, the only way I can see to achieve this is by having a checkbox or multi-select, but neither of these options are desirable for me because I want them to either pick one or none.

Thanks in advance.

- Aaron

#763533

There's not an option to do this in the GUI, but you could use some JavaScript to insert the placeholder option programmatically. Another ticket I worked on recently discussed this approach in some detail:
https://toolset.com/forums/topic/cred-module-edit-post-choice-taxonomy-does-not-work/
This ticket also includes some backend validation messages that you may or may not want to include. Let me know if you have questions about this approach.

#774559
temp.jpg

Hi Christian,

I tried implementing a solution using a similar approach using this JavaScript:


$('.prependoptions').prepend($('<option>--- none selected ---</option>')); 

..and then setting the class of the cred field to "prependoptions". This way I could just assign this class to any taxonomy field on the site and have it prepend the option list without needing JavaScript for each one. However, when I add the class to the field like this...


[cred_field field='religion' class="prependoptions" display='select' single_select="true" output='bootstrap']

..the class does not appear in the HTML when I inspect the page (see attached image). I was actually having a similar issue with featured image shortcode earlier (not taking a manually assigned class) so I guess my question is a broader one now: am I doing something wrong in trying to assign a class?

- Aaron

#777518

Update - the issue with the featured image not taking a manually assigned class was resolved by upgrading from Views 2.6-RC to Views 2.6-RC2. However, the class set in the cred_field tag is still not translating over to the actual select tag in the HTML output.

#778586

Thanks for the report, we currently have an internal ticket in place to address the issue with classes being applied inconsistently in cred_field shortcodes. Most likely this will be addressed after the stable M2M release. For now, it's probably more practical to use a wrapping div to target the select field, like this:

<div class="prependoptions">
[cred_field ... ]
</div>
jQuery('.prependoptions select').prepend...