Jump to:

22998 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » CountryDropdownField Default Country

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: 1921 Views
  • Jonn
    Avatar
    Community Member
    10 Posts

    CountryDropdownField Default Country Link to this post

    Hi,

    I'm trying to build a custom form for a page with a country dropdown and I can't get it to show the country I want selected rather than just the first entry.

    new CountryDropdownField(
    $name = 'Country',
    $title = 'Country',
    $value = 'US'
    )

    I noticed the the API I can call $isSelected but I not sure where/how to implement this. The userforms module now has a country dropdown but again I cant see where to set the default country.

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: CountryDropdownField Default Country Link to this post

    Having a quick look at the API for the field the constructor states that the default value is the 4th argument rather than the 3rd which could be the solution. You may also want to disable the defaultToVisitorCountry check if GeoIP doesn't work.

    http://api.silverstripe.org/2.4/forms/fields-relational/CountryDropdownField.html

  • Jonn
    Avatar
    Community Member
    10 Posts

    Re: CountryDropdownField Default Country Link to this post

    Thanks Willr, I got both my custom forms and userforms working correctly now.

  • datswicked
    Avatar
    Community Member
    15 Posts

    Re: CountryDropdownField Default Country Link to this post

    Just found this post and have done this in SS3.0.4 as below, might be useful for others..

    static $db = array(
    'BirthPlace' => 'Varchar(255)'
    );
    static $default_country = 'AU';

    public function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main',new CountryDropdownField('BirthPlace', 'Birth Place'));
    return $fields;
    }

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