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.

Archive /

Our old forums are still available as a read-only archive.

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

About CMSFields, Default Values and Required Fields...


Go to End


2 Posts   2237 Views

Avatar
dio5

Community Member, 501 Posts

3 December 2007 at 2:55am

1) I was trying to set a default value for an OptionSetField in the cms, but just can't get it to work. Part of the code I used was http://pastie.caboo.se/124284.. tried a couple of other things too but just didn't get it to work. Note that I'm also using the populateDefaults method, so maybe that is interfering/overwriting?

2) How can I set some fields as required? Can I do a new RequiredFields somewhere? Is there any method for it?

thnx

Avatar
dio5

Community Member, 501 Posts

3 December 2007 at 3:00am

ok..

When doing

$countries = DataObject::get("Country");
$this->CountryID = $countries->First()->ID;

in the populateDefaults method it seems to work. Apparently setting a default value in the getcmsfields-method doesn't mix with it.

Still interested in knowing how to make fields required in the backend though.