Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » String value instead of index from the Dropdownfield

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: 384 Views
  • ville
    Avatar
    Community Member
    5 Posts

    String value instead of index from the Dropdownfield Link to this post

    Hey,

    I have a form which contains a dropdownfield in the following format: new DropdownField('Reproducibility', 'Reproducibility', array('Always','Sometimes','Randomly','Have not tried'))

    When I'm trying to get the string values, it's giving array index instead of string values. How can I retrieve the real values which are shown in the dropdownfield?

    Thanks!

  • jak
    Avatar
    Community Member
    46 Posts

    Re: String value instead of index from the Dropdownfield Link to this post

    The value of the dropdown field is determined by the key in the array you are passing. Since you do not set the keys, they are numeric. Try something like

    new DropdownField('Reproducibility', 'Reproducibility',
    array('always' => 'Always', 'sometimes'=>'Sometimes', 'randomly'=>'Randomly', 'nottried' => 'Have not tried'));


    Avoid spaces in the keys.

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