Sauter la navigation

[Résolu] How to add placeholder or first select option for post form drop downs?

This support ticket is created Il y a 5 années et 4 mois. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nigel Il y a 5 années et 4 mois.

Assisté par: Nigel.

Auteur
Publications
#1322601
Screen Shot 2019-08-22 at 7.32.31 PM.png

I'm trying to create a blank select option for drop down fields in a CRED from the says "Choose your [field_name]" instead of the default --not set--

Is is possible?

#1322825

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Dallin

This is actually harder than it should be, and the first thing I'd do is recommend you submit a request for it to be possible to set alternate option labels when nothing is selected in the UI itself where you insert the field: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

It can be done, but requires some—simple—coding, so add a new snippet for this at Toolset > Settings > Custom Code.

The following is an example where I am changing the label for a couple of select fields which is simple enough that you should be able to see what I'm doing. Note that Types fields use a wpcf- prefix, so my "Assignee" field is referenced with wpcf-assignee, etc.

function ts_update_notset( $not_set_value, $attributes, $data ){

    if ( $data['name'] == 'wpcf-assignee' ) {
        $not_set_value['#title'] = '-- Choose Assignee --';
    }

    if ( $data['name'] == 'wpcf-priority' ) {
        $not_set_value['#title'] = '-- Set Priority --';
    }

    return $not_set_value;
}
add_filter( 'wpt_field_not_set_option', 'ts_update_notset', 10, 3 );

Can you try that?