|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\HTML\Renderable; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Field; |
|
6
|
|
|
use Formularium\HTMLElement; |
|
7
|
|
|
|
|
8
|
|
|
class Renderable_number extends \Formularium\Renderable implements \Formularium\Frontend\HTML\RenderableInterface |
|
9
|
|
|
{ |
|
10
|
|
|
public const STEP = 'step'; |
|
11
|
|
|
public const MIN = "min"; |
|
12
|
|
|
public const MAX = "max"; |
|
13
|
|
|
|
|
14
|
|
|
use \Formularium\Frontend\HTML\RenderableViewableTrait; |
|
15
|
|
|
|
|
16
|
|
|
public function editable($value, Field $f, HTMLElement $previous): HTMLElement |
|
17
|
|
|
{ |
|
18
|
|
|
$input = new HTMLElement('input'); |
|
19
|
|
|
/** @var \Formularium\Datatype\Datatype_number $datatype */ |
|
20
|
|
|
$datatype = $f->getDatatype(); |
|
21
|
|
|
|
|
22
|
|
|
$extensions = $f->getExtensions(); |
|
23
|
|
|
$validators = $f->getValidators(); |
|
24
|
|
|
$input->setAttributes([ |
|
25
|
|
|
'type' => ($extensions[static::HIDDEN] ?? false ? 'hidden' : 'number'), |
|
26
|
|
|
'name' => $f->getName(), |
|
27
|
|
|
'class' => '', |
|
28
|
|
|
'data-attribute' => $f->getName(), |
|
29
|
|
|
'data-datatype' => $datatype->getName(), |
|
30
|
|
|
'data-basetype' => $datatype->getBasetype(), |
|
31
|
|
|
'value' => $value, |
|
32
|
|
|
'title' => $f->getExtension(static::LABEL, '') |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
if (isset($extensions[static::PLACEHOLDER])) { |
|
36
|
|
|
$input->setAttribute('placeholder', $extensions[static::PLACEHOLDER]); |
|
37
|
|
|
} |
|
38
|
|
|
foreach ([static::DISABLED, static::READONLY, static::REQUIRED] as $v) { |
|
39
|
|
|
if ($f->getExtension($v, false)) { |
|
40
|
|
|
$input->setAttribute($v, $v); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (array_key_exists(static::STEP, $validators)) { |
|
45
|
|
|
$input->setAttribute('step', $validators[static::STEP]); |
|
46
|
|
|
} |
|
47
|
|
|
if (isset($extensions[static::NO_AUTOCOMPLETE])) { |
|
48
|
|
|
$input->setAttribute('autocomplete', 'off'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$container = new HTMLElement('div', [], $input); |
|
52
|
|
|
if (array_key_exists('label', $extensions)) { |
|
53
|
|
|
$container->prependContent(new HTMLElement('label', [], $extensions['label'])); |
|
54
|
|
|
} |
|
55
|
|
|
return $container; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|