Home › Toolset Professional Support › [Resolved] Show no data found message on generic field if view is empty
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.
Our next available supporter will start replying to tickets in about 0.27 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
This topic contains 6 replies, has 3 voices.
Last updated by himanshuS 1 year, 10 months ago.
Assisted by: Minesh.
I am using a view to show data on a generic field in a form.
When there is data in the view, all works well. When there is no data, the view publishes No Data Found as a shortcode but publishes nothing as a entry to generic field. How can I show no data found in the generic field?
[cred_show_group if="( ( $(existing-job-check) eq '2' ) )" mode="fade-slide"] <div class="form-group" style="Display:none;"> <label for="%%FORM_ID%%_post_title">[cred_i18n name='post_title-label']Job Title[/cred_i18n]<span class="red-color">*</span></label> [cred_field field='post_title' class='form-control' output='bootstrap' value='Temp job'] </div> <p>Select a job<span class="red-color">*</span></p> [cred_generic_field type='select' field='job-post'] { "required":1, "options":[ [wpv-view name="job-posts-dropdown-for-project-prompt"] ] } [/cred_generic_field] [/cred_show_group]
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
In this scenario you are using the View to output JSON to provide options to the options parameter of the cred_generic_field shortcode.
That options parameter can only accept options settings in JSON format, so that is what your View must provide, whether it returns any results or not.
So, edit your View, and edit the no-items-found section so that it returns a single option with no value and the text you prefer (e.g. "No options found") in the same JSON format as is used when there are results.
Nigel,
Thanks a lot. If I do that, won't the user be able to select the "no options found" field and proceed with submission.
The generic field has a required condition on it. I think it will accept no "options found".
Then, I would need to add another validation that checks for empty ID (in the No options found selection) and stop user from submitting the post. Is that accurate or is there is a better way to avoid user from progressing with post submission?
If you do not want to add extra validation then maybe you should add the "No option found" option as suggested by Nigel to the no-items-found section and set the value of this option to 0 - will that work?
Minesh,
0 is still a value. I am not sure if the required condition on generic field does not consider 0 as a value. Does it?
I know 0 is still a value - but you do not have any other option to select with "no items found" so you can skip extra validation step here - does that makes sense?
Or
If you do not agree with this then what you shared is also correct. That you should validate the field value from the backend as well.
My issue is resolved now. Thank you!