Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

8533 Posts in 2224 Topics by 1200 members

General Questions

SilverStripe Forums » General Questions » Default selected value - OptionsetField

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

Page: 1
Go to End
Author Topic: Default selected value - OptionsetField 276 Views
  • quamsta
    avatar
    Community Member
    21 posts

    Default selected value - OptionsetField Link to this post

    Hi, I'm having some issues changing the default selected value when I make an OptionsetField in Page.php for use inside SilverStripe.

    Here is my code:

       new OptionsetField(
           $name = 'Options',
           $title = 'Options',
           $source = singleton('Page')->dbObject('Options')->enumValues(),
           $value = "2"
           )

    However, no matter what I set "$value" to, whenever I create a new page in the CMS, the first option is always selected. Does anyone know why this is the case?
          

  • tobych
    avatar
    Community Member
    96 posts

    Re: Default selected value - OptionsetField Link to this post

    I don't really know what the code for the $source is doing, but the documentation is here - http://doc.silverstripe.com/doku.php?id=optionsetfield - and note that $value refers to the index used in the $source array, not the number of the element in that array. Sorry, language is failing me here, but if your $source is

    2 => "Apple"
    54 => "Orange"
    512 => "Banana"

    then $value="2" will mean the default will be "Apple".

    276 Views
Page: 1
Go to Top

Currently Online: Hamish, sicp

Welcome to our latest member: fearofbuttons

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

Comments on this website? Please give feedback.