Problem: I am following the tutorial to conditionally display parent posts in a CRED form:
https://toolset.com/2013/10/conditional-display-of-parent-posts-in-cred/
I would like to be able to define a default option label in my generated select field.
Solution: Add an empty option to the beginning of the list of aux_anmelder_ids in the auxiliary View:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div id="aux_anmelder_list" style="display:none">
<div class="aux_anmelder_id"></div>
<wpv-loop>
<div class="aux_anmelder_id">[wpv-post-id]</div>
</wpv-loop>
</div>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Then change the JavaScript code to accept an empty string value instead of defaulting to zero:
$('.aux_anmelder_id', list).each(function(index, element) {
var id = $(element).text();
$('option[value="' + id + '"]', select).appendTo(new_select);
});
This should copy the unset value from the original select field into the cloned select field. Change the select_text attribute here from "bitte auswählen" to "wer wird angemeldet"
[cred_field field='_wpcf_belongs_person_id' value='' select_text='bitte auswählen' class='form-control' output='bootstrap']
Relevant Documentation: https://toolset.com/2013/10/conditional-display-of-parent-posts-in-cred/