Is it possible to remove the 'Not Set' option from the parent selection list on a child CRED post form?
I tried adding this to the JS editor but it removed the whole list!
jQuery(document).ready(function($){
$("select[name='_wpcf_belongs_parent-post-slug_id'] option:first").remove();
});
Many thanks
Have you tried to modify the ShortCode?
It has a select_text attribute
That is the Text used there. If you leave it empty, it will still take "-- not set--" but if you put your custom value there it will respect it.
I also requested the Developers to enhance this, and make it possible to output nothing at all.
Thanks for putting it to the developers.
Removing the current default to leave an empty field isn't what I was hoping for.
I've thought about possibilities for a work around and I tried using a generic field like this:-
[cred_generic_field field='_wpcf_belongs_parent-post_id' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="parent-post-titles"] ]
}
[/cred_generic_field]
where the View is based on the Parent post type and the author is same as current logged in user and the loop output editor contains this:-
[wpv-item index=1]
{"value":"[wpv-post-title id="$parent-post"]","label":"Parent"}
[wpv-item index=other]
,{"value":"[wpv-post-title id="$parent-post"]","label":"Parent"}
but nothing is displayed. I guess that's because at the time of creating the Child post, a relationship doesn't exist yet.
So I tried this in the View instead:-
[wpv-item index=1]
{"value":"[wpv-post-title]","label":"Parent"}
[wpv-item index=other]
,{"value":"[wpv-post-title]","label":"Parent"}
but that didn't display anything either.
I guess I'll just have to wait for the developer to do their bit but would you mind indulging my curiosity and let me know why my work around isn't working please?
Many thanks
Views should not be used to populate ShortCodes.
Views wraps its results in a default HTML and that will break your JSON.
THere are custom functions, to avoid that, but it is not suggested to use them.
You would, in that case, need some custom code like this:
https://toolset.com/forums/topic/how-to-display-view-results-inline-or-specify-div-class/#post-350852
Hi Beda
Sorry for the delay in getting back to you. I'll have a look at the custom code you've referred to although I'd be happier if the developers can find a way of allowing us to remove the '---not set---' option. Have they responded to your request about this?
Thanks
Yes, we will use the select_text='' attribute like this in future:
- if Types values are set, and no value in the select_text='', then Types values will take over
- if no Types, and no select_text='' (the Attribute is removed), then nothing will appear as not set (this will remove the --not set--)
Does this make sense to you as well?
I must correct myself:
- select_text='[whatevervalue]' is not empty, will be seen on frontend
- select_text='' is empty, empty value will be seen on frontend
- select_text is not present as attribute (means is null) so default — not set — will be seen on frontend (like on backend types)
Sorry no I'm not getting it.
Forget the cred generic field for the moment and go back to my original question. The parent selection list on a child post form automatically appears on a child post form. We don't 'set it up' in any way do we (by adding custom values as you've mentioned)? I've no idea what happens in the background to populate that list - all I know is the list comprises the post titles of all the child post's possible parents plus a default ---not set--- option. I would just like the default option to be the first parent in the list.
You could not set the default value to be the first parent available, but you can set it to be empty, or any Custom Value.
I will ask if it is possible to remove that option at all, but i do not think so, as you also need to possibility to set nothing, this possibility always should be open.
Thanks for offering to ask if it's achievable.
I do however disagree with your statement that there HAS to be an option to set nothing. In this scenario, we're talking about a pick list that sets the parent for the post so the exact opposite is true ; if we allow the User to leave the selection blank (or 'not set'), the parent/child relationship won't be created when the post is submitted and that means unexpected/incorrect results being returned in Views for example. Or am I missing something?
This is all fixed in the current CRED release.
The default value should be changed in Types.