21282 Posts in 5730 Topics by 2601 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1407 Views |
-
CountryDropdownField Default Country

30 December 2010 at 4:15pm
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
-
Re: CountryDropdownField Default Country

1 January 2011 at 6:14pm
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
-
Re: CountryDropdownField Default Country

4 January 2011 at 1:20pm
Thanks Willr, I got both my custom forms and userforms working correctly now.
-
Re: CountryDropdownField Default Country

8 March 2013 at 11:11am
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;
}
| 1407 Views | ||
|
Page:
1
|
Go to Top |


