Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ModelAdmin: Length limitation on Varchar

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

Page: 1
Go to End
Author Topic: 1819 Views
  • xeraa
    Avatar
    Google Summer of Code Hacker
    58 Posts

    ModelAdmin: Length limitation on Varchar Link to this post

    In my model I've defined: 'Title' => 'Varchar(32)',

    In the ModelAdmin I can enter any number of characters and successfully save the object - if I've entered more than 32 characters in the title they are also displayed after saving.
    If I reload the object, the title it is cut off after 32 characters (as the database simply doesn't store more than this). I would have expected / hoped for some kind of warning when trying to save more than the possible characters - currently they are lost without any kind of message.

    Is this a bug, am I doing something wrong or how can this be fixed?

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: ModelAdmin: Length limitation on Varchar Link to this post

    I'm not sure ModelAdmin (or any of the CMS form fields) provide this sort of automatic validation for lengths of data. You can set the max length of the TextField (eg 32) in the constructor but don't think a nice error message will be generated (just won't allow any more characters) the form valldation is one of the areas on the todo list.

  • xeraa
    Avatar
    Google Summer of Code Hacker
    58 Posts

    Re: ModelAdmin: Length limitation on Varchar Link to this post

    Thanks for pointing that out. The following did the trick:

       function getCMSFields(){
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Main', new TextField('Title', 'Title', '', 32), 'Subtitle');
          $fields->addFieldToTab('Root.Main', new TextField('Subtitle', 'Subtitle', '', 64), 'Text');
          return $fields;
       }

    Would be cool if SilverStripe could do that automagically as the current cutting of is definitely not nice.
    I guess there is no point in filing a ticket as this is already on the roadmap?

    1819 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.