-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathform5.php
More file actions
92 lines (64 loc) · 3.14 KB
/
form5.php
File metadata and controls
92 lines (64 loc) · 3.14 KB
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
<?php
declare(strict_types=1);
namespace Atk4\Ui\Demos;
use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Ui\App;
use Atk4\Ui\Columns;
use Atk4\Ui\Form;
use Atk4\Ui\Js\JsToast;
use Atk4\Ui\View;
/** @var App $app */
require_once __DIR__ . '/../init-app.php';
View::addTo($app, [
'Forms below focus on Data integration and automated layouts',
'ui' => 'ignored warning message',
]);
$formSubmit = static function (Form $form) use ($app) {
return new JsToast($app->encodeJson($form->entity->get()));
};
$cc = Columns::addTo($app);
$form = Form::addTo($cc->addColumn());
// adding field without model creates a regular line
$form->addControl('one');
// array second is a default seed for default line field
$form->addControl('three', ['caption' => 'Caption2']);
// use zeroth argument of the seed to specify standard class
$form->addControl('four', [Form\Control\Checkbox::class, 'caption' => 'Caption2']);
// use explicit object for user-defined or 3rd party field
$form->addControl('five', new Form\Control\Checkbox(), ['type' => 'boolean'])->set(true);
// objects still accept seed
$form->addControl('six', new Form\Control\Checkbox(['caption' => 'Caption3']));
$form->onSubmit($formSubmit);
$model = new Model(new Persistence\Array_());
// model field uses regular line form control by default
$model->addField('one');
// caption is a top-level property of a field
$model->addField('two', ['caption' => 'Caption']);
// ui can also specify caption which is a form-specific
$model->addField('three', ['ui' => ['form' => ['caption' => 'Caption']]]);
// type is converted into CheckBox form control with caption as a seed
$model->addField('four', ['type' => 'boolean', 'ui' => ['form' => ['caption' => 'Caption2']]]);
// can specify class for a checkbox explicitly
// type here in "six" should not be needed if we add Checkbox form control support for string type
$model->addField('five', ['type' => 'boolean', 'ui' => ['form' => [Form\Control\Checkbox::class, 'caption' => 'Caption3']]]);
// Form-specific caption overrides general caption of a field. Also you can specify object instead of seed
$model->addField('six', ['type' => 'boolean', 'caption' => 'badcaption', 'ui' => ['form' => new Form\Control\Checkbox(['caption' => 'Caption4'])]]);
$model = $model->createEntity();
$form = Form::addTo($cc->addColumn());
$form->setEntity($model);
$form->onSubmit($formSubmit);
// next form won't initialize default fields, but we'll add them individually
$form = Form::addTo($cc->addColumn());
$form->setEntity($model, []);
// adding that same field but with custom form control seed
$form->addControl('one', ['caption' => 'Caption0']);
// we can override type, but seed from model will still be respected
$form->addControl('three', [Form\Control\Checkbox::class]);
// we override type and caption here
$form->addControl('four', [Form\Control\Line::class, 'caption' => 'CaptionX']);
// we can specify form control object, it's still seeded with caption from model
$form->addControl('five', new Form\Control\Checkbox());
// can add field that does not exist in a model
$form->addControl('nine', new Form\Control\Checkbox(['caption' => 'Caption3']));
$form->onSubmit($formSubmit);