|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Materialize\Renderable; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Field; |
|
6
|
|
|
use Formularium\HTMLNode; |
|
7
|
|
|
use Formularium\Frontend\HTML\Renderable\Renderable_enum as HTMLRenderable_enum; |
|
8
|
|
|
use Formularium\Frontend\Materialize\RenderableMaterializeTrait; |
|
9
|
|
|
|
|
10
|
|
|
class Renderable_enum extends \Formularium\Renderable |
|
11
|
|
|
{ |
|
12
|
|
|
use RenderableMaterializeTrait; |
|
13
|
|
|
|
|
14
|
|
|
public function viewable($value, Field $field, HTMLNode $previous): HTMLNode |
|
15
|
|
|
{ |
|
16
|
|
|
return $previous; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Subcall of wrapper editable() from RenderableMaterializeTrait |
|
21
|
|
|
* |
|
22
|
|
|
* @param mixed $value |
|
23
|
|
|
* @param Field $field |
|
24
|
|
|
* @param HTMLNode $previous |
|
25
|
|
|
* @return HTMLNode |
|
26
|
|
|
*/ |
|
27
|
|
|
public function _editable($value, Field $field, HTMLNode $previous): HTMLNode |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$newContent = []; |
|
30
|
|
|
$format = $field->getRenderable(HTMLRenderable_enum::FORMAT_CHOOSER, HTMLRenderable_enum::FORMAT_CHOOSER_SELECT); |
|
31
|
|
|
|
|
32
|
|
|
if ($format == HTMLRenderable_enum::FORMAT_CHOOSER_RADIO) { |
|
33
|
|
|
$labels = []; |
|
34
|
|
|
// add extra classes |
|
35
|
|
|
foreach ($previous->get('.formularium-radio-item') as $container) { |
|
36
|
|
|
$label = $container->get('label')[0]; |
|
37
|
|
|
$input = $container->get('input')[0]; |
|
38
|
|
|
$labels[] = HTMLNode::factory('p', [], $label->prependContent($input)); |
|
39
|
|
|
} |
|
40
|
|
|
$previous->setContent($labels); |
|
41
|
|
|
} else { |
|
42
|
|
|
// add extra classes |
|
43
|
|
|
$input = $previous->get('select'); |
|
44
|
|
|
$input[0]->removeAttribute('class'); |
|
45
|
|
|
$id = $input[0]->getAttribute('id')[0]; |
|
46
|
|
|
$newContent[] = $input[0]; |
|
47
|
|
|
$label = $previous->get('label'); |
|
48
|
|
|
if (!empty($label)) { |
|
49
|
|
|
$newContent[] = $label[0]; |
|
50
|
|
|
} |
|
51
|
|
|
$comment = $previous->get('.formularium-comment'); |
|
52
|
|
|
if (!empty($comment)) { |
|
53
|
|
|
$comment[0]->setTag('span')->setAttributes([ |
|
54
|
|
|
'class' => 'helper-text', |
|
55
|
|
|
'data-error' => "wrong", |
|
56
|
|
|
'data-success' => "right" |
|
57
|
|
|
]); |
|
58
|
|
|
$newContent[] = $comment[0]; |
|
59
|
|
|
} |
|
60
|
|
|
$script = HTMLNode::factory( |
|
61
|
|
|
'script', |
|
62
|
|
|
[], |
|
63
|
|
|
"document.addEventListener('DOMContentLoaded', function() { |
|
64
|
|
|
var elems = document.querySelectorAll('#${id}'); |
|
65
|
|
|
var options = {}; |
|
66
|
|
|
var instances = M.FormSelect.init(elems, options); |
|
67
|
|
|
});", |
|
68
|
|
|
true |
|
69
|
|
|
); |
|
70
|
|
|
$newContent[] = $script; |
|
71
|
|
|
$previous->setContent($newContent); |
|
72
|
|
|
} |
|
73
|
|
|
return $previous; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.