blob: c5a614cd74e918893402d929ff277756eb29770d (
plain)
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
|
<?php
namespace ipl\Web\FormElement\TermInput;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Web\FormElement\TermInput;
class TermContainer extends BaseHtmlElement
{
protected $tag = 'div';
protected $defaultAttributes = ['class' => 'terms'];
/** @var TermInput */
protected $input;
/**
* Create a new TermContainer
*
* @param TermInput $input
*/
public function __construct(TermInput $input)
{
$this->input = $input;
}
protected function assemble()
{
foreach ($this->input->getTerms() as $i => $term) {
$label = $term->getLabel() ?: $term->getSearchValue();
$this->addHtml(new HtmlElement(
'label',
Attributes::create([
'class' => $term->getClass(),
'data-search' => $term->getSearchValue(),
'data-label' => $label,
'data-index' => $i
]),
new HtmlElement(
'input',
Attributes::create([
'type' => 'text',
'value' => $label,
'pattern' => $term->getPattern(),
'data-invalid-msg' => $term->getMessage()
])
)
));
}
}
}
|