forked from xu-chris/multiselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiselect.php
100 lines (72 loc) · 2.11 KB
/
multiselect.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
class MultiselectField extends CheckboxesField {
public $search = true;
static public $assets = array(
'css' => array(
'multiselect.css'
),
'js' => array(
'multiselect.js'
)
);
public function __construct() {
$this->icon = 'chevron-down';
}
public function input() {
$value = func_get_arg(0);
$input = parent::input($value);
return str_replace('required','', $input);
}
public function item($value, $text) {
$input = $this->input($value);
$label = new Brick('label');
$label->addClass('input');
$label->attr('data-focus', 'true');
$text = new Brick('span', $this->i18n($text));
$label->prepend($text);
$label->prepend($input);
if($this->readonly) {
$label->addClass('input-is-readonly');
}
return $label;
}
public function content() {
$multiselect = new Brick('div');
$multiselect->addClass('input input-display');
if($this->readonly()) $multiselect->addClass('input-is-readonly');
$multiselect->data(array(
'field' => 'multiselect',
'search' => $this->search ? 1 : 0,
'readonly' => ($this->readonly or $this->disabled) ? 1 : 0,
));
$multiselect->append('<div class="placeholder"> </div>');
$content = new Brick('div');
$content->addClass('field-content input-with-multiselectbox');
$content->append($multiselect);
// list with options
$html = '<div class="input-list">';
if ($this->search) {
$html .= '<input class="multiselectbox-search" placeholder="Type to filter options">';
}
$html .= '<ul>';
foreach($this->options() as $key => $value) {
$html .= '<li class="input-list-item">';
$html .= $this->item($key, $value);
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
$content->append($html);
$content->append($this->icon());
return $content;
}
public function label() {
$label = parent::label();
$label->attr('for', '');
return $label;
}
public function result() {
$result = parent::result();
return empty($result) ? null : $result;
}
}