/
select.php
56 lines (52 loc) · 1.71 KB
/
select.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class DingesSelect extends DingesInputField {
protected $element = 'select';
protected $options = array();
// IE (iig 6) selecteert het eerste element als je op het label klikt
protected $realLabelTag = false;
function addItem($value, $content, $optgroup = NULL) {
$option = array('value' => $value, 'content' => htmlspecialchars($content, ENT_NOQUOTES, NULL, false));
if($optgroup) {
$this->options[$optgroup][] = $option;
} else {
$this->options[] = $option;
}
}
function fillAttributes() {
parent::fillAttributes();
if(isset($this->attributes['multiple'])) {
$this->setAttribute('name', $this->name .'[]');
}
}
function generateHTML() {
$value = $this->getEffectiveValue();
$options = '';
foreach($this->options as $i=>$option) {
if(!isset($option['value'])) {
$optgroup = '';
foreach($option as $suboption) {
$attributes = array('value' => $suboption['value']);
if($suboption['value'] == $value) {
$attributes['selected'] = 'selected';
}
$optgroup .= DingesForm::generateTag('option', $attributes, $suboption['content']);
}
$options .= DingesForm::generateTag('optgroup', array('label' => $i), $optgroup);
continue;
}
$attributes = array('value' => $option['value']);
if(is_array($value)) {
if(in_array($option['value'], $value)) {
$attributes['selected'] = 'selected';
}
} else {
if($option['value'] == $value) {
$attributes['selected'] = 'selected';
}
}
$options .= DingesForm::generateTag('option', $attributes, $option['content']);
}
return DingesForm::generateTag($this->element, $this->attributes, $options) . $this->getRestrictionComment();
}
}
?>