Skip Navigation

[Resolved] Post Relationship form select only showing 10 items

This support ticket is created 3 years, 2 months ago. 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Julie Tuerk 3 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2203047

Tell us what you are trying to do? I'd like the select box to show all options, not just 10. I tried to add an attribute to the shortcode, but that didn't work. [cred-relationship-role role='parent' orderby='title' order='ASC' limit='40']

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link Password: health

#2204471

Hi,

Thank you for contacting us and I'd be happy to assist.

I tried to see the form on the link you shared, but it was showing the message "No items found".

By default, the post-relationship field added through the "cred-relationship-role" shortcode ( ref: https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-relationship-role ) shows the input field with a "select2" script that shows more autocomplete options, as you type.
( screenshot: hidden link )

I'm afraid, there is no built-in option available to disable this autocomplete feature, but, If you're not seeing more options for autocomplete, you're welcome to share temporary admin login details, so that I can see how this form is set up in the admin area.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2208057

Hello I haven't received a reply in 3 days. Can someone please check on this?

#2208577

Thank you for waiting and I apologize for the delay in getting back on this.

During testing and research, I couldn't find any built-in function or option to change the behaviour of the post-relationship selection field.

To have a regular select field, which shows all parent "EHRs" posts, you can follow these steps, as a workaround:

1. You'll need to register a custom shortcode, which can get the list of all available parent "EHRs" posts and create a custom regular select field, which includes only those posts as options, which are not already connected:


add_shortcode('create_shadow_parent_field', 'create_shadow_parent_field_func');
function create_shadow_parent_field_func() {

	$parent_post_slug = 'ehr';
	$relationship_slug = 'ehr-relationship';

	$current_post = do_shortcode('[wpv-post-id]');

	// get parent posts which are already connected
	$get_results = toolset_get_related_posts($current_post, $relationship_slug, 'child', 9999, 0, array(), 'post_id', 'parent');

	// get all the parent posts
	$args = array(
		'post_type'        => $parent_post_slug,
		'posts_per_page'   => -1,
		'post_status'      => 'publish',
	);

	$posts_array = get_posts( $args );
	// create a custom select field from the available parent posts, which are not already connected
	ob_start();

	if(!empty($posts_array)) {
		echo '<select id="shadow_parent_selector" name="shadow_parent_selector"><option value="">-select-</option>';
		foreach ($posts_array as $result) {
			if(!in_array($result->ID, $get_results)) {
				echo '<option value="'.$result->ID.'">'.$result->post_title.'</option>';
			}
		};
		echo '</select>';

	}

	return ob_get_clean();

}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

2. Next, in your relationship form, you can hide ( but not remove ) the actual parent post field added through the "cred-relationship-role" shortcode and include this custom select field, by adding this new shortcode [create_shadow_parent_field].

3. And in the form's JS editor, you'll include this script that will detect selection changes in this custom select field and update them in the hidden parent selection field:


jQuery( document ).ready(function() {
	jQuery('select#shadow_parent_selector').on('change', function() {
		var selectVal = this.value;
		var selectText = jQuery(this).find("option:selected").text();
		if( selectVal > 0) {
			jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
			jQuery('#cred_association_ehr-relationship_parent').append(jQuery('<option>', { value: selectVal, text: selectText }));
		}
		else 
		{
			jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
		}
	});
});

As a result, the user will see the regular select field which shows all options at once, but, the selection will be updated in the actual autocomplete field too.

I hope this helps and please let me know if you need any further assistance around this.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2208967
Screenshot (50).png
Screenshot (49).png
Screenshot (48).png

Thanks that works great to display all the EHR choices. One question: we are using the same form to update EHRs as well as create new ones. Here on the Select2 form, we have it displaying the EHR name from the list on the update form. I have the new form next to it. Is there a way to get the new form to do this?
If you login to Julie's HCCN using the login credentials, you will see "Add New EHR" and "Add Support Services to EHR" If you click Add Support Services, you will see what I mean, or the screenshots might tell you enough.

#2210761

Thanks for the update and glad that it worked.

From your message and screenshots, I understand that you'd like to pre-select the value that is selected in the default select2 input field, into the new custom select field too.
( screenshot: hidden link )

If that is correct, you can update the custom script from the last message to:


jQuery( document ).ready(function() {
	var preSelectedVal = jQuery('#cred_association_ehr-relationship_parent').find(":selected").val();
	jQuery("select#ehr_parent_selector").val(preSelectedVal);
	
	jQuery('select#ehr_parent_selector').on('change', function() {
		var selectVal = this.value;
		var selectText = jQuery(this).find("option:selected").text();
		if( selectVal > 0) {
		jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
			jQuery('#cred_association_ehr-relationship_parent').append(jQuery('<option>', { value: selectVal, text: selectText }));
		}
		else
		{
			jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
		}
	});
});

#2213073

My issue is resolved now. Thank you!