Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Getting unique values for dropdown

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: 1149 Views
  • sca123
    Avatar
    Community Member
    61 Posts

    Getting unique values for dropdown Link to this post

    I am using two dropdowns in a search function for the blog. So, what I need to do is get the unique values for field x and then turn the results into a dropdown - can anyone help?

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Getting unique values for dropdown Link to this post

    The 2 simplest options off the top of my head:

    1. Post the form back and have a conditional add of the second form if the first dropdown is set. Psudocode:

    // form code
    if( isset($data['firstDropDown'] } (
    $fields->push( new DropDownField('secondDropDown','Second: ',array('otherdata')) );
    }

    // form post function
    if( ! isset($data['firstDropDown'] ) {
    Director::redirectBack();
    }

    2. Use jQuery or something with an Ajax Action button on the first dropdown to create/populate the second dropdown. Docs: http://doc.silverstripe.org/doku.php?id=ajaxformaction

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