Skip Navigation

[Escalated to 2nd Tier] Can't add class to select element in CRED form

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

This topic contains 4 replies, has 2 voices.

Last updated by Beda 5 years ago.

Assisted by: Nigel.

Author
Posts
#1370501

Hello!

I am trying to add a css class to a select element in CRED but it isn't getting added in the front end

Link to a page where the issue can be seen: hidden link

I expected to see the selects with the corresponding classed I've defined in the backend as:
[cred_field field='localizacion' force_type='taxonomy' display='select' class='province']
[cred_field field='localizacion' force_type='taxonomy' output='bootstrap' display='select' single_select="true" class="location"]

Ive tried with single quotes, double quotes, with bootstrap output, without it... But nothing seems to be working.

From what I've seen here (https://toolset.com/documentation/user-guides/styling-cred-forms/) select is an element that accepts injecting classes to it.

Any idea what I may be doing wrong?

Thanks a lot!

#1370559

When you insert a Generic Select Field in Toolset Form and add an additional Custom Class, it will be added to the HTML that the Select Field generates.
You can see the in the console after saving the form and visiting it in the front end.

Types Select Fields do not allow to add a Class in the Toolset Forms Editor.
But, you can still add a class='custom-class' when in the Advanced editor, and that will as well reflect on the front end.

This would be the Form Code:

[cred_field field='select-of-types' force_type='field' class='form-control custom-class-here' output='bootstrap']

It this is not working on your end, I suggest to ensure it is not due to malformed ShortCodes, or 3rd Party code (you can temporarily disable other Plugins and use another theme to be sure).

However note, this is for select fields, as you requested.
But the ShortCode you show me is not a select field - instead it's a Taxonomy Field that accidentally is displayed as select input.
This is different.

There you can only use the wpt-form-select class which is used by all select inputs of Forms
It is closer explained here https://toolset.com/documentation/user-guides/styling-cred-forms/#hierarchical-taxonomy
But that DOC is out of date, I see.
Currently there is no class added to the Taxonomy inputs as stated there, neither to the wrapping DIV.
I've reported that to the 2nd Tier for analysis.

Right now, you can open the Browser console and analyze the Input HTML, it will tell exactly what class or name you can address, however, you cannot add your custom class to it.

You can for example use the classes wpt-form-select form-select select, or the HTML "name" attribute, which will be something like "your_taxonomy_singular_slug[]"
Example:

select[name="your_tax[]"] {
  background: red;
}

I will keep you in the loop about our updates to either DOC or bug fixing in Toolset Forms to adjust the current discrepancies.

#1370945

Thanks a ton for the detailed response Beda!

As you mentioned, the problem is that it was a taxonomy field (which is being displayed as a select and I thought it would be treated as such by Toolset, but is is't). It indeed would be a nice thing to be able to add a custom class to these elements too.

I really needed a custom class to perform some things with javascript, so I ended up adding those classes with Javascript once the document is loaded. It'd be better to have this ability baked into the framework, but at least it works.

Hope you guys can implement this in the future ; )

Thanks again for the awesome answer!

#1370947

My issue is resolved now. Thank you!

#1463383

The amendments I suggested to Doc are not yet made, so I reopen and re-escalate this here in order to update you when it's fixed.