Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » form // addExtraClass

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

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

Page: 1
Go to End
Author Topic: 942 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    form // addExtraClass Link to this post

    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.

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: form // addExtraClass Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: form // addExtraClass Link to this post

    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.

    942 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.