1 <?php
2 3 4 5 6 7
8 class OptionsetField extends DropdownField {
9
10 11 12
13 protected $disabledItems = array();
14
15 16 17 18 19 20 21 22
23 function __construct($name, $title = "", $source = array(), $value = "", $form = null) {
24 parent::__construct($name, $title, $source, $value, $form);
25 }
26
27 28 29 30 31 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) {
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
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 75 76 77 78
79 function setDisabledItems($items) {
80 $this->disabledItems = $items;
81 }
82
83 84 85
86 function getDisabledItems() {
87 return $this->disabledItems;
88 }
89
90 function () {
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.
-