Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • CheckboxField
  • CheckboxField_Disabled
  • CheckboxField_Readonly
  • CheckboxSetField
  • DropdownField
  • GroupedDropdownField
  • ListboxField
  • LookupField
  • NullableField
  • OptionsetField
  • ReadonlyField
  • RoomServiceDropdownField
  • SimpleHTMLEditorField
  • SimpleTinyMCEField
  • SimpleWysiwygField
  • StateDropdownField
  • StateProvinceDropdownField
  • TextareaField
  • TextField
 1 <?php
 2 /**
 3  * Set of radio buttons designed to emulate a dropdown.
 4  * It even uses the same constructor as a dropdown field.
 5  * @package forms
 6  * @subpackage fields-basic
 7  */
 8 class OptionsetField extends DropdownField {
 9     
10     /**
11      * @var Array
12      */
13     protected $disabledItems = array();
14     
15     /**
16      * Creates a new optionset field.
17      * @param name The field name
18      * @param title The field title
19      * @param source An map of the dropdown items
20      * @param value The current value
21      * @param form The parent form
22      */
23     function __construct($name, $title = "", $source = array(), $value = "", $form = null) {
24         parent::__construct($name, $title, $source, $value, $form);
25     }
26 
27     /**
28      * Create a UL tag containing sets of radio buttons and labels.  The IDs are set to
29      * FieldID_ItemKey, where ItemKey is the key with all non-alphanumerics removed.
30      * 
31      * @todo Should use CheckboxField FieldHolder rather than constructing own markup.
32      */
33     function Field() {
34         $options = '';
35         $odd = 0;
36         $source = $this->getSource();
37         foreach($source as $key => $value) {
38             $key_lat = Convert::rus2lat($key);
39             $itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+','', $key_lat);
40 
41             if($key == $this->value/* || $useValue */) {
42                 $useValue = false;
43                 $checked = " checked=\"checked\"";
44             } else {
45                 $checked="";
46             }
47             
48             $odd = ($odd + 1) % 2;
49             $extraClass = $odd ? "odd" : "even";
50             $extraClass .= " val" . preg_replace('/[^a-zA-Z0-9\-\_]/','_', $key_lat);
51             $disabled = ($this->disabled || in_array($key, $this->disabledItems)) ? 'disabled="disabled"' : '';
52             
53             $options .= "<li class=\"".$extraClass."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" /> <label for=\"$itemID\">$value</label></li>\n";
54         }
55         $id = $this->id();
56         return "<ul id=\"$id\" class=\"optionset {$this->extraClass()}\">\n$options</ul>\n";
57     }
58     
59     protected $disabled = false;
60     function setDisabled($val) {
61         $this->disabled = $val;
62     }
63     
64     function performReadonlyTransformation() {
65         // Source and values are DataObject sets.
66         $items = $this->getSource();
67         $field = new LookupField($this->name,$this->title ? $this->title : "" ,$items,$this->value);
68         $field->setForm($this->form);
69         $field->setReadonly(true);
70         return $field;
71     }
72     
73     /**
74      * Mark certain elements as disabled,
75      * regardless of the {@link setDisabled()} settings.
76      * 
77      * @param array $items Collection of array keys, as defined in the $source array
78      */
79     function setDisabledItems($items) {
80         $this->disabledItems = $items;
81     }
82     
83     /**
84      * @return Array
85      */
86     function getDisabledItems() {
87         return $this->disabledItems;
88     }
89     
90     function ExtraOptions() {
91         return new DataObjectSet();
92     }
93 }
94 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0