Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

form // addExtraClass


Go to End


3 Posts   1605 Views

Avatar
dacar

Community Member, 173 Posts

13 July 2011 at 9:44pm

Hi,

every time i use addExtraClass on my forms i get a space before the classname. Is there a way to avoid this?

$anredeField = new DropdownField('Anrede', 'Anrede', $listsForAnrede);
$anredeField->ExtraClass('select');

<select name="Anrede" id="Form_SubscribeForm_Anrede" class=" select"><option value="Herr">Herr</option><option value="Frau">Frau</option></select>

Greetings, Carsten.

Avatar
MarijnKampf

Community Member, 176 Posts

1 August 2011 at 6:54pm

The space is added in case there are already classes defined, have you tried calling extraClass(), according to the API (http://api.silverstripe.org/2.4/forms/core/Form.html#methodextraClass) it compiles all css classes, although I'm not 100% sure it means it will get rid of the leading space.

Avatar
Willr

Forum Moderator, 5523 Posts

3 August 2011 at 7:26pm

I guess it may always put a ' ' before everything just to be safe. It shouldn't cause any issues as [space] won't be a valid classname. If you want to dig in and get it resolved have a look around where it prints the select tag, you probably need to use trim() around value put into the class attribute.