Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Userform State Dropdown


Reply


6 Posts   1868 Views

Avatar
Graphicator

Community Member, 62 Posts

8 January 2011 at 1:01am

Edited: 08/01/2011 1:02am

I added a Field for US States, and wondered where I can post this class for people in the US to add State dropdowns to their forms. Unless this is already included and i overlooked it.

moduledirectory/code/editor/EditableStateDropDown.php

class EditableStateDropDown extends EditableFormField {
   
      static $singular_name = 'State Field';
      
      static $plural_name = 'State Fields';

      
      function getFormField() {
         $labelField = new DropdownField($this->Name, $this->Title, GetStates::getStateDropDown());
         $labelField->addExtraClass('FormState');
         return $labelField;
      }

   }

moduledirectory/code/integration/GetStates .php

class GetStates {
   
   protected static $us_stateCodes = array(
   'None Selected' => "Select",
   'Outside US' => "Outside US",
   'AL' => "Alabama",
   'AK' => "Alaska",
   'Alberta' => "Alberta",
   'AZ' => "Arizona",
   'AR' => "Arkansas",
   'Br. Columbia' => "Br. Columbia",
   'CA' => "California",
   'CO' => "Colorado",
   'CT' => "Connecticut",
   'DE' => "Delaware",
   'DC' => "District of Columbia",
   'FL' => "Florida",
   'GA' => "Georgia",
   'Guam' => "Guam",
   'HI' => "Hawaii",
   'ID' => "Idaho",
   'IL' => "Illinois",
   'IN' => "Indiana",
   'IA' => "Iowa",
   'KS' => "Kansas",
   'KY' => "Kentucky",
   'LO' => "Louisiana",
   'ME' => "Maine",
   'Manitoba' => "Manitoba",
   'MD' => "Maryland",
   'MA' => "Massachusetts",
   'MI' => "Michigan",
   'MN' => "Minnesota",
   'MS' => "Mississippi",
   'MO' => "Missouri",
   'MT' => "Montana",
   'NE' => "Nebraska",
   'NV' => "Nevada",
   'New Brunswick' => "New Brunswick",
   'NH' => "New Hampshire",
   'NJ' => "New Jersey",
   'NM' => "New Mexico",
   'NY' => "New York",
   'Newfoundland' => "Newfoundland",
   'NC' => "North Carolina",
   'ND' => "North Dakota",
   'Nova Scotia' => "Nova Scotia",
   'OH' => "Ohio",
   'OK' => "Oklahoma",
   'Ontaria' => "Ontario",
   'OR' => "Oregon",
   'PA' => "Pennsylvania",
   'Pr. Edward Isl.' => "Pr. Edward Island",
   'PR' => "Puerto Rico",
   'Quebec' => "Quebec",
   'RI' => "Rhode Island",
   'Saskatchewan' => "Saskatchewan",
   'SC' => "South Carolina",
   'SD' => "South Dakota",
   'TN' => "Tennessee",
   'TX' => "Texas",
   'UT' => "Utah",
   'VT' => "Vermont",
   'VA' => "Virginia",
   'WA' => "Washington",
   'WV' => "West Virginia",
   'WI' => "Wisconsin",
   'WY' => "Wyoming"
   );

   /**
    * Returns an array of State Names
    */
   static function getStateDropDown() {
      $dropdown = GetStates::$us_stateCodes;
      asort($dropdown);
      return $dropdown;
   }
}

Avatar
Willr

Forum Moderator, 5513 Posts

8 January 2011 at 8:27pm

I added a Field for US States, and wondered where I can post this class for people in the US to add State dropdowns to their forms. Unless this is already included and i overlooked it.

It is not already included. Not sure it's useful enough to be included in the default installation. Perhaps just keep it attached to the forum, you can optionally submit the field type as a module.

Avatar
Graphicator

Community Member, 62 Posts

8 January 2011 at 10:18pm

I added these userforms extension to my new github. Just learned how to commit + push changes today.
My additional custom fields are US States, and a Non Editable Field (with Default in the Extra Options)

https://github.com/graphicagenda/Extending-Silverstripe-Module--Userform/tree/

My question to Willr is, how do we call an image for the field, the one with the pencil... without uploading it into the main userforms module?

Avatar
Willr

Forum Moderator, 5513 Posts

9 January 2011 at 7:02pm

You can define a function getIcon on your class which returns the path.

function getIcon() {
return 'yourmodule/images/foo.png';
}

Avatar
socks

Community Member, 190 Posts

13 March 2011 at 9:45pm

I believe it's

function Icon() {
return 'yourmodule/images/foo.png';
}

And thanks Graphicator, I've been wanting that US States dropdown in Userforms forever.

Avatar
Willr

Forum Moderator, 5513 Posts

15 March 2011 at 10:00pm

https://github.com/silverstripe/silverstripe-userforms/blob/master/code/editor/EditableFormField.php#L169

SSViewer automatically trims any 'get' off for the templates.