Skip Navigation

[Gelöst] Conditional display of parent posts – no default text

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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/

This support ticket is created vor 7 Jahren. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Matthias Reichl vor 7 Jahren.

Assistiert von: Christian Cox.

Author
Artikel
#591990

I am trying to:
Only show selected parent posts in select field
I followed the instructions under
https://toolset.com/2013/10/conditional-display-of-parent-posts-in-cred/
The limitation of parent posts works perfectly, the correct posts are being displayed

Link to a page where the issue can be seen:
versteckter Link

I expected to see:
a default text in the select field "wer wird angemeldet"

Instead, I got:
no default text

MY CRED FORM

[credform class='cred-form cred-keep-original']

[wpv-view name="liste-der-miglieder-und-gaeste-im-aktuellen-clubjahr"]

	[cred_field field='form_messages' value='' class='alert alert-warning']

	<div class="form-group">
		<label>Anmeldung</label>
		[cred_field field='post_title' post='anmeldung' value='Anmeldung' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>Wer wird angemeldet</label>
		[cred_field field='_wpcf_belongs_person_id' value='' select_text='bitte auswählen' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>Für welche Veranstaltung</label>
		[cred_field field='_wpcf_belongs_veranstaltung_id' value='' select_text='bitte auswählen' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>Anzahl</label>
		[cred_field field='anzahl' post='anmeldung' value='' urlparam='' select_text='bitte auswählen' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>Bemerkungen</label>
		[cred_field field='post_content' post='anmeldung' value='' urlparam='' output='bootstrap']  
	</div>

	[cred_field field='form_submit' value='Speichern' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

MY JS CODE

jQuery(document).ready(function($) {
    try {
        var select = $('select[name="_wpcf_belongs_person_id"]');
        var list = $('#aux_anmelder_list') || $('div id="aux_anmelder_list">');
          if (select.length) {
            var selected = select.val();
            var new_select = select.clone(true, true);
            new_select.children().remove();
            $('.aux_anmelder_id', list).each(function(index, element) {
                var id = $(element).text() || 0;
                $('option[value="' + id + '"]', select).appendTo(new_select);
            });
            new_select.val(selected);
            select.replaceWith(new_select);
        }
    } catch(e) {
    }
});

MY AUXILIARY VIEW

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
      <div id="aux_anmelder_list" style="display:none">
        <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]
#592299

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

a default text in the select field "wer wird angemeldet"
You must 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']
#592364

Hi Christian!

Works perfectly - thanks a lot.