Skip Navigation

[Resolved] Place view inside generic field

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a generic radio field in a Form, and use a View to define the options for the field. The View does not seem to be working and the radio options are not set correctly.

Generic field shortcode with View shortcode for options:

[cred_generic_field field='organization-select-generic' type='radio']
{
"required":0,
"default":[],
"options":[ [wpv-view name="organization-select-generic" raw="true"] ]
}
[/cred_generic_field]

View Loop Output editor content:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>{"value":"[wpv-post-id]","label":"[wpv-post-title]"},</wpv-loop>{"value":"","label":"None"}
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Solution: The shortcodes look okay, but there is probably some extra space in the View output that is breaking the input field options. To fix this, copy the contents of the Loop Output editor panel. Then run the Loop Wizard to create some simple loop using the loop style "List with separators". This will automatically strip extra spaces from the View's output. After you complete the wizard, overwrite everything by pasting in your original content.

Other minor things: remove the "raw" attribute from the View shortcode, and remove the "No items found" message when no results are found. Leave it blank or create a dummy radio option.

This support ticket is created 4 years, 9 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
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)

This topic contains 2 replies, has 2 voices.

Last updated by Nicholas 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1528711

Dear Toolset Team.
I am trying to place a view inside a generic field and was wondering if that's possible and recommend to do?

[cred_generic_field field='organization-select-generic' type='radio']
{
"required":0,
"default":[],
"options":[ [wpv-view name="organization-select-generic" raw="true"] ]
}
[/cred_generic_field]

This is what my view looks like in detail:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>{"value":"[wpv-post-id]","label":"[wpv-post-title]"},</wpv-loop>{"value":"","label":"None"}
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

The wrapping DIV around the view is also disabled.

What do you recommend?

#1529175

If you use the Loop Wizard and select "List with separators", then the View will automatically have spaces removed so it doesn't break the radio options. If you don't choose that option, you may not get the best results. I would copy everything you have in the loop output editor, then click Loop Wizard. Add something basic in the loop just to complete the wizard. Then after it's complete and you see the code, delete it all, and paste your content back in the loop editor. Try that first, then let me know if you still have problems.

If that fixes the problems, you should delete the no results found line or replace it with something to create one default option:

[wpml-string context="wpv-views"]No items found[/wpml-string]

...and the "raw" attribute here doesn't do anything, you can remove it unless you have some custom code in place that relies on it:

 [wpv-view name="organization-select-generic" raw="true"]
#1530779

My issue is resolved now. Thank you!