Jump to:

10842 Posts in 2513 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Userform State Dropdown

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1723 Views
  • Graphicator
    Avatar
    Community Member
    62 Posts

    Userform State Dropdown Link to this post

    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;
       }
    }

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Userform State Dropdown Link to this post

    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.

  • Graphicator
    Avatar
    Community Member
    62 Posts

    Re: Userform State Dropdown Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Userform State Dropdown Link to this post

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

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

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Userform State Dropdown Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Userform State Dropdown Link to this post

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