[Resolved] Many enries in a Toolsert form select

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.

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 5 months, 2 weeks ago.

Assigned support staff: Waqar.

Author
Posts
#1360271

Hi, I've a 4 CPTs:

Reports
Supplements
Conditions
Product

Then I've these relationships:

Supplements-Conditions many-to-many
Supplements-Product one-to-many

Reports-Supplements one-to-many
Reports-Conditions one-to-many
Reports-Product one-to-many

I create Reports by a Toolset Form, so there I've to create the relationships selecting Supplements, Conditions, Product.

I'm going to have almost 10.000 entries for products and 1000 Supplements and Conditions.

Is it a problem to load all that entries in the Form selects? Is it going to be very slow?

Has they are connected by relationships, when I select a Supplement, I could reduce the number of the products in the Products select. I know I can do it by a custom select with views, but I should create a multy step flow where I reload the page to filter products. Is there a way to do it dinamically with AJAX?

thanks

#1361051

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Umberto,

Thank you for waiting.

I've performed some tests on my own website and can confirm that the built-in relationships fields can only be used to show all the available post lists.
( same as on your test form at hidden link )

In order to achieve what you're planning, you can replace the relationship fields for the products and conditions with regular generic fields of type "select", making sure that the field names, remain the same.
( i.e. @condition-report.parent & @product-report.parent )

Next, you can attach a custom script that triggers when the value of the supplement field is selected/changed, and based on the selected value, populate only the relevant products and conditions, in their respective field, through AJAX.

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

regards,
Waqar

#1361239

Hi, I'm trying to setup a Select2 Ajax (remote data). I've preapred a view that to output the correct json format, this is an example of the output of the view:

"results": [

{
"id": 95,
"text": "Pure Encapsulations Magnesium Glycinate"
},
{
"id": 96,
"text": "Nobi Nutrition Magnesium Complex"
},
{
"id": 98,
"text": "Nature’s Bounty Magnesium"
},
{
"id": 100,
"text": "KAL Magnesium Glycinate"
}

]}

Now my problem is where can I put this view so Select2 can use it as remote data? This is the Select2 JS I should use:

jQuery('.js-data-example-ajax').select2({
ajax: {
url: 'hidden link',
dataType: 'json'
}
});

I made a test adding the json text code in an empty php file and it works. But if I put the json View on a page the select doesn't work.

How can I output the view in an empty (no HTML tags) page?

thanks

#1361835

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Umberto,

Although this is something not specifically related to Toolset plugins, we do our best to guide in the right direction, whenever possible.

1. You can use "render_view" function to get the output of your post view, into a PHP code or template:
https://toolset.com/documentation/programmer-reference/views-api/#render_view

2. The actual steps to create a blank page template for a WordPress page will vary, based on the active theme, but you'll find the basic steps and concept in these guides:

hidden link
hidden link

3. Your current approach of using a static page's URL ( e.g. hidden link ) for the AJAX call is not considered safe and is against WordPress development standards.

As we discussed in the chat, you should be using WordPress built-in file ( hidden link ), for processing such AJAX requests, as explained with example code snippets in this guide:
hidden link

This way, you won't have to create a separate static page or page template for this.

Note: For more personalized assistance around general WordPress features and functions, you can post your questions at the specialized forums like:

https://wordpress.org/support/
https://wordpress.stackexchange.com/

regards,
Waqar