phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
DataFormHelper.php
Go to the documentation of this file.
1<?php
3
5use Ubiquity\contents\validation\ValidatorsManager;
6use Ubiquity\orm\OrmUtils;
7
9
15 public static function defaultFields(DataForm $form): void {
16 $form->setFields(OrmUtils::getFormAllFields($form->getModel()));
17 }
18
24 public static function defaultUIConstraints(DataForm $form): void {
25 self::addDefaultUIConstraints($form, OrmUtils::getFieldTypes($form->getModel()), ValidatorsManager::getUIConstraints($form->getModelInstance()));
26 }
27
34 public static function addDefaultUIConstraints(DataForm $form, array $fieldTypes, array $uiConstraints): void {
35 foreach ($fieldTypes as $property => $type) {
36 $rules = $uiConstraints[$property] ?? [];
37 if ($hasRules = \count($rules) > 0) {
38 $form->setValidationParams([
39 "on" => "blur",
40 "inline" => true
41 ]);
42 }
43 $noPName = false;
44 $noPType = false;
45 switch ($property) {
46 case 'password':
47 $form->fieldAsInput($property, [
48 'inputType' => 'password'
49 ] + $rules);
50 break;
51 case 'email':
52 case 'mail':
53 $form->fieldAsInput($property, $rules);
54 break;
55 default:
56 $noPName = true;
57 }
58
59 switch ($type) {
60 case 'tinyint(1)':
61 case 'bool':
62 case 'boolean':
63 $form->fieldAsCheckbox($property, \array_diff($rules['rules'] ?? [], [
64 'empty'
65 ]));
66 break;
67 case 'int':
68 case 'integer':
69 $form->fieldAsInput($property, [
70 'inputType' => 'number'
71 ] + $rules);
72 break;
73 case 'date':
74 $form->fieldAsInput($property, [
75 'inputType' => 'date'
76 ] + $rules);
77 break;
78 case 'datetime':
79 $form->fieldAsInput($property, [
80 'inputType' => 'datetime-local'
81 ] + $rules);
82 break;
83 case 'text':
84 $form->fieldAsTextarea($property, $rules);
85 break;
86 default:
87 $noPType = true;
88 }
89 if ($hasRules && $noPName && $noPType) {
90 $form->fieldAsInput($property, $rules);
91 }
92 }
93 }
94}
setValidationParams(array $_validationParams)
Sets the parameters for the Form validation (on, inline, delay...)
Definition Widget.php:497
static defaultFields(DataForm $form)
Adds the instance members as form fields.
static addDefaultUIConstraints(DataForm $form, array $fieldTypes, array $uiConstraints)
static defaultUIConstraints(DataForm $form)
Adds the default ui constraints to the form.
fieldAsCheckbox($index, $attributes=NULL)
fieldAsTextarea($index, $attributes=NULL)
fieldAsInput($index, $attributes=NULL)