I have a generic select field in a CRED form to which I provide values via View.
Via a cred_submit_complete action I use the selected value to link to a post in a related parent CPT.
When I use a similar generic select field in a CRED Edit form, I want to display the title of the linked post in the drop-down of the generic select field, instead of the normal "-- not set--" text.
My plan was to use select_text="[wpv-post-title item='@funnel-type-of-funnel.parent']" in the CRED shortcode.
However, even before I tried that, I did a test using select_text='My Text Here' but that had no effect.
So my question is: how can I over-ride the "-- not set--" text with my linked post title?
For reference, here is the code of the CRED field:
<label>Select a Funnel Type</label>
[cred_generic_field type='select' field='funnel-type-lookup' select_text='My Text Here' class='kam-generic-selector']
{
"required":1,
"options":[ [wpv-view name='asset-json' post_type='funnel-types'] ]
}
[/cred_generic_field]
Thanks
Hi Alex,
Thank you for contacting us.
I apologize for the delay, as I had an unusually busy queue after the weekend.
Unlike the "cred_field" shortcode ( ref: https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field ), the "cred_generic_field" shortcode ( ref: https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field ) doesn't support a parameter to override the default select text option ( i.e. "-- not set--" ).
If you'd like to remove the first default select option so that only the ones coming from the custom shortcode are shown, you can add some custom script in the form's "JS editor" tab:
jQuery( document ).ready(function() {
jQuery('select.kam-generic-selector').find('option').get(0).remove();
});
I hope this helps and you're welcome to submit a feature request to add support for the "select_text" parameter in the "cred_generic_field" shortcode as well:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
regards,
Waqar
Thanks, Waqar
It's useful to know that I can't force the default to appear, so I won't spend time experimenting. I will submit a feature request, as you suggested.
I don't understand what you mean by "remove the first default select option". Could you explain what that would achieve, please?
I inserted the jQuery code you provided, but I couldn't see any difference to the form's display. I also tried changing "option" to "options", but that caused the whole View to disappear!
But maybe I don't need what it is you're suggesting, so that's the main thing to clarify for now.
Thanks
Alex
Hi Alex,
Sorry if my message caused some confusion. I'll be happy to clarify.
When we use a custom shortcode with a generic field to dynamically generate select field options, the first select option is added by the field, followed by the options from the shortcode.
Screenshot: lien caché
The example script code that I shared would remove that default first option, for someone who doesn't want it.
Screenshot: lien caché
In case that code didn't work in your form, please make sure that the correct class name ( e.g. "kam-generic-selector") assigned to that select field is used in the code and there are no script errors in the browser's console.
( ref: https://codex.wordpress.org/Using_Your_Browser_to_Diagnose_JavaScript_Errors )
regards,
Waqar
Thanks for the clarification, Waqar. I can now see why you suggested that option for me - appreciated.
My issue is resolved now. Thank you!
Regards
Alex