-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.php
84 lines (81 loc) · 2.44 KB
/
model.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
<?php
use Formularium\Datatype;
use Formularium\Datatype\Datatype_string;
use Formularium\Field;
use Formularium\Frontend\HTML\Renderable\Renderable_number;
use Formularium\Frontend\HTML\Renderable\Renderable_string;
use Formularium\Model;
use Formularium\Renderable;
use Formularium\Validator\Max;
use Formularium\Validator\MaxLength;
use Formularium\Validator\Min;
use Formularium\Validator\MinLength;
// our own datatype. You can (and should) use autoload for this, too.
require('./Datatype_aaaaa.php');
require('./Renderable_aaaaa.php');
function modelData(): Model
{
// build the model from data description. You can use a JSON file as well.
$modelData = new Model(
'TestModel',
);
$modelData->appendField(new Field(
'myString',
Datatype_string::class,
[
Renderable::LABEL => 'This is some string',
Renderable::COMMENT => 'At least 3 characters but no more than 10',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type here",
Renderable::ICON_PACK => 'fas',
Renderable::ICON => 'fa-check'
],
[
MinLength::class => [
'value' => 3,
],
MaxLength::class => [
'value' => 10,
],
Datatype::REQUIRED => [
'value' => true,
]
],
))->appendField(new Field(
'someInteger',
'integer',
[
Renderable_number::STEP => 2,
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::LABEL => 'Some integer',
Renderable::COMMENT => 'Between 4 and 30',
Renderable::PLACEHOLDER => "Type here"
],
[
Min::class => [
'value' => 4,
],
Max::class => [
'value' => 30,
],
Datatype::REQUIRED => [
'value' => true,
]
],
))->appendField(new Field(
'myaaaaa',
'aaaaa',
[
Renderable::LABEL => 'This is a custom datatype',
Renderable::COMMENT => 'Fill this with aaaaa to validate properly',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type aaaaa here"
],
[
Datatype::REQUIRED => [
'value' => true,
]
],
));
return $modelData;
}