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
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.
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
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.
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...