From 79c5f61252ca8150564bfb4f4f8f380ff2f65be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 19 Aug 2022 02:05:17 +0200 Subject: [PATCH] Fix '0' instead of '' default value for Lookup (#1816) --- demos/_includes/Demo.php | 1 + demos/_includes/SomeData.php | 13 ++++++------- demos/basic/columns.php | 1 + demos/form/form2.php | 1 + demos/init-db.php | 5 +++++ docs/form-control.rst | 1 + docs/form.rst | 1 + docs/multiline.rst | 1 + src/CardDeck.php | 1 + src/CardSection.php | 1 + src/Component/InlineEdit.php | 1 + src/Form.php | 1 + src/Form/Control/Dropdown.php | 4 ++-- src/Form/Control/Lookup.php | 2 +- src/Grid.php | 1 + src/HelloWorld.php | 1 + src/JsSortable.php | 1 + src/LoremIpsum.php | 1 + src/Modal.php | 1 + src/Panel/Content.php | 1 + src/Panel/Right.php | 1 + src/Table/Column/ActionButtons.php | 1 + src/Table/Column/ActionMenu.php | 5 ----- src/Table/Column/Checkbox.php | 1 + src/Table/Column/FilterModel.php | 1 + src/Table/Column/KeyValue.php | 5 ----- src/UserAction/ConfirmationExecutor.php | 1 + src/UserAction/ExecutorFactory.php | 4 +++- src/UserAction/ModalExecutor.php | 1 + src/UserAction/PanelExecutor.php | 1 + src/UserAction/VpExecutor.php | 1 + src/View.php | 1 + 32 files changed, 42 insertions(+), 21 deletions(-) diff --git a/demos/_includes/Demo.php b/demos/_includes/Demo.php index 21c884df30..1df8db4cc7 100644 --- a/demos/_includes/Demo.php +++ b/demos/_includes/Demo.php @@ -18,6 +18,7 @@ class Demo extends \Atk4\Ui\Columns protected function init(): void { parent::init(); + $this->addClass('celled'); $this->left = $this->addColumn($this->leftWidth); diff --git a/demos/_includes/SomeData.php b/demos/_includes/SomeData.php index 29f074e961..f14d07b845 100644 --- a/demos/_includes/SomeData.php +++ b/demos/_includes/SomeData.php @@ -16,13 +16,12 @@ public function __construct() protected function init(): void { parent::init(); - $model = $this; - $model->addField('title'); - $model->addField('name'); - $model->addField('surname', ['actual' => 'name']); - $model->addField('date', ['type' => 'date']); - $model->addField('salary', ['type' => 'atk4_money', 'actual' => 'randomNumber']); - $model->addField('logo_url'); + $this->addField('title'); + $this->addField('name'); + $this->addField('surname', ['actual' => 'name']); + $this->addField('date', ['type' => 'date']); + $this->addField('salary', ['type' => 'atk4_money', 'actual' => 'randomNumber']); + $this->addField('logo_url'); } } diff --git a/demos/basic/columns.php b/demos/basic/columns.php index 1c2837ff3f..e7e5b65717 100644 --- a/demos/basic/columns.php +++ b/demos/basic/columns.php @@ -72,6 +72,7 @@ protected function init(): void { parent::init(); + \Atk4\Ui\Table::addTo($this, ['header' => false]) ->setSource(['One', 'Two', 'Three', 'Four']); } diff --git a/demos/form/form2.php b/demos/form/form2.php index c7cf1a2f52..07cb1a27fa 100644 --- a/demos/form/form2.php +++ b/demos/form/form2.php @@ -88,6 +88,7 @@ protected function init(): void { parent::init(); + $this->addField('name', ['required' => true]); $this->addField('surname', ['ui' => ['placeholder' => 'e.g. Smith']]); $this->addField('gender', ['enum' => ['M', 'F']]); diff --git a/demos/init-db.php b/demos/init-db.php index bd9cc0dff2..aae278364f 100644 --- a/demos/init-db.php +++ b/demos/init-db.php @@ -160,6 +160,7 @@ class Country extends ModelWithPrefixedFields protected function init(): void { parent::init(); + $this->addField($this->fieldName()->name, ['actual' => 'atk_afp_country__nicename', 'required' => true, 'type' => 'string']); $this->addField($this->fieldName()->sys_name, ['actual' => 'atk_afp_country__name', 'system' => true]); @@ -307,6 +308,7 @@ class File extends ModelWithPrefixedFields protected function init(): void { parent::init(); + $this->addField($this->fieldName()->name); $this->addField($this->fieldName()->type, ['caption' => 'MIME Type']); @@ -403,6 +405,7 @@ class Category extends ModelWithPrefixedFields protected function init(): void { parent::init(); + $this->addField($this->fieldName()->name); $this->hasMany($this->fieldName()->SubCategories, [ @@ -428,6 +431,7 @@ class SubCategory extends ModelWithPrefixedFields protected function init(): void { parent::init(); + $this->addField($this->fieldName()->name); $this->hasOne($this->fieldName()->product_category_id, [ @@ -454,6 +458,7 @@ class Product extends ModelWithPrefixedFields protected function init(): void { parent::init(); + $this->addField($this->fieldName()->name); $this->addField($this->fieldName()->brand); $this->hasOne($this->fieldName()->product_category_id, [ diff --git a/docs/form-control.rst b/docs/form-control.rst index b6c4d36658..bfdb40f9ef 100644 --- a/docs/form-control.rst +++ b/docs/form-control.rst @@ -153,6 +153,7 @@ The most common use-case in large application is the use with Models. You would protected function init(): void { parent::init(); + $this->addField('name', ['actual' => 'nicename', 'required' => true, 'type' => 'string']); $this->addField('sys_name', ['actual' => 'name', 'system' => true]); diff --git a/docs/form.rst b/docs/form.rst index d9c8f75a01..4cffc00413 100644 --- a/docs/form.rst +++ b/docs/form.rst @@ -490,6 +490,7 @@ Example use of Model's validate() method:: protected function init(): void { parent::init(); + $this->addField('name', ['required' => true]); $this->addField('surname'); $this->addField('gender', ['enum' => ['M', 'F']]); diff --git a/docs/multiline.rst b/docs/multiline.rst index bf9fb79c01..9618955495 100644 --- a/docs/multiline.rst +++ b/docs/multiline.rst @@ -148,6 +148,7 @@ Lets use the example of demos/multiline.php:: protected function init(): void { parent::init(); + $this->addField('item', ['required' => true, 'default' => 'item']); $this->addField('qty', ['type' => 'integer', 'caption' => 'Qty / Box', 'required' => true, 'ui' => ['multiline' => ['sui-table-cell' => ['width' => 2]]]]); $this->addField('box', ['type' => 'integer', 'caption' => '# of Boxes', 'required' => true, 'ui' => ['multiline' => ['sui-table-cell' => ['width' => 2]]]]); diff --git a/src/CardDeck.php b/src/CardDeck.php index d374bf72c8..2d9b46b323 100644 --- a/src/CardDeck.php +++ b/src/CardDeck.php @@ -94,6 +94,7 @@ class CardDeck extends View protected function init(): void { parent::init(); + $this->container = $this->add($this->container); if ($this->menu !== false) { diff --git a/src/CardSection.php b/src/CardSection.php index 114ee1a7af..4f37e9f3d1 100644 --- a/src/CardSection.php +++ b/src/CardSection.php @@ -22,6 +22,7 @@ class CardSection extends View protected function init(): void { parent::init(); + $this->addClass('content'); } diff --git a/src/Component/InlineEdit.php b/src/Component/InlineEdit.php index df34a28006..8b562ed2c9 100644 --- a/src/Component/InlineEdit.php +++ b/src/Component/InlineEdit.php @@ -72,6 +72,7 @@ class InlineEdit extends View protected function init(): void { parent::init(); + $this->cb = \Atk4\Ui\JsCallback::addTo($this); // Set default validation error handler. diff --git a/src/Form.php b/src/Form.php index 631aecc45f..a642d16c29 100644 --- a/src/Form.php +++ b/src/Form.php @@ -228,6 +228,7 @@ public function setModel(Model $model, array $fields = null): void // Model is set for the form and also for the current layout try { parent::setModel($model); + $this->layout->setModel($model, $fields); } catch (Exception $e) { throw $e->addMoreInfo('model', $model); diff --git a/src/Form/Control/Dropdown.php b/src/Form/Control/Dropdown.php index 3df8d2ff95..1a6bccc51a 100644 --- a/src/Form/Control/Dropdown.php +++ b/src/Form/Control/Dropdown.php @@ -215,7 +215,7 @@ protected function htmlRenderValue(): void // add selection only if no value is required and Dropdown has no multiple selections enabled if ($this->entityField !== null && !$this->entityField->getField()->required && !$this->isMultiple) { $this->_tItem->set('value', ''); - $this->_tItem->set('title', $this->empty || is_numeric($this->empty) ? (string) $this->empty : ''); + $this->_tItem->set('title', $this->empty); $this->template->dangerouslyAppendHtml('Item', $this->_tItem->renderToHtml()); } @@ -282,7 +282,7 @@ protected function renderView(): void parent::renderView(); } - // Sets the dropdown items to the template if a model is used + // sets the dropdown items to the template if a model is used protected function _renderItemsForModel() { foreach ($this->model as $key => $row) { diff --git a/src/Form/Control/Lookup.php b/src/Form/Control/Lookup.php index 1da05849fd..c19ee66269 100644 --- a/src/Form/Control/Lookup.php +++ b/src/Form/Control/Lookup.php @@ -182,7 +182,7 @@ public function getData($limit = true): array } if (!$this->multiple && $this->empty) { - array_unshift($data, ['value' => '0', 'title' => (string) $this->empty]); + array_unshift($data, ['value' => '', 'title' => $this->empty]); } return $data; diff --git a/src/Grid.php b/src/Grid.php index e6a361e09a..9ec75d6e61 100644 --- a/src/Grid.php +++ b/src/Grid.php @@ -92,6 +92,7 @@ class Grid extends View protected function init(): void { parent::init(); + $this->container = View::addTo($this, ['template' => $this->template->cloneRegion('Container')]); $this->template->del('Container'); diff --git a/src/HelloWorld.php b/src/HelloWorld.php index 63f7187e06..f8cbcf79d2 100644 --- a/src/HelloWorld.php +++ b/src/HelloWorld.php @@ -12,6 +12,7 @@ class HelloWorld extends View protected function init(): void { parent::init(); + $this->set('Content', 'Hello World'); } } diff --git a/src/JsSortable.php b/src/JsSortable.php index 44f5501813..acb2e7cda8 100644 --- a/src/JsSortable.php +++ b/src/JsSortable.php @@ -41,6 +41,7 @@ class JsSortable extends JsCallback protected function init(): void { parent::init(); + if (!$this->view) { $this->view = $this->getOwner(); } diff --git a/src/LoremIpsum.php b/src/LoremIpsum.php index 884bf7e394..916906b070 100644 --- a/src/LoremIpsum.php +++ b/src/LoremIpsum.php @@ -96,6 +96,7 @@ public function __construct($defaults = null) protected function init(): void { parent::init(); + for ($x = 0; $x < $this->size; ++$x) { $this->addParagraph($this->generateLorem($this->words * $this->size)); } diff --git a/src/Modal.php b/src/Modal.php index 057f398f0f..eba71069dd 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -65,6 +65,7 @@ class Modal extends View protected function init(): void { parent::init(); + $this->getApp()->registerPortals($this); } diff --git a/src/Panel/Content.php b/src/Panel/Content.php index ab28c63405..1801a7494e 100644 --- a/src/Panel/Content.php +++ b/src/Panel/Content.php @@ -18,6 +18,7 @@ class Content extends View implements LoadableContent protected function init(): void { parent::init(); + $this->addClass('atk-panel-content'); $this->setCb(new Callback()); } diff --git a/src/Panel/Right.php b/src/Panel/Right.php index c300858557..1037574f0f 100644 --- a/src/Panel/Right.php +++ b/src/Panel/Right.php @@ -58,6 +58,7 @@ class Right extends View implements Loadable protected function init(): void { parent::init(); + if ($this->dynamic) { $this->addDynamicContent(Factory::factory($this->dynamic)); } diff --git a/src/Table/Column/ActionButtons.php b/src/Table/Column/ActionButtons.php index 79884b4168..72f8d4d1b8 100644 --- a/src/Table/Column/ActionButtons.php +++ b/src/Table/Column/ActionButtons.php @@ -26,6 +26,7 @@ class ActionButtons extends Table\Column protected function init(): void { parent::init(); + $this->addClass('right aligned'); } diff --git a/src/Table/Column/ActionMenu.php b/src/Table/Column/ActionMenu.php index c112b98673..fcab126ace 100644 --- a/src/Table/Column/ActionMenu.php +++ b/src/Table/Column/ActionMenu.php @@ -41,11 +41,6 @@ class ActionMenu extends Table\Column /** @var string Button icon to use for display dropdown. */ public $icon = 'dropdown icon'; - protected function init(): void - { - parent::init(); - } - public function getTag(string $position, $value, $attr = []): string { if ($this->table->hasCollapsingCssActionColumn && $position === 'body') { diff --git a/src/Table/Column/Checkbox.php b/src/Table/Column/Checkbox.php index e4082af2f2..870b5a6fb2 100644 --- a/src/Table/Column/Checkbox.php +++ b/src/Table/Column/Checkbox.php @@ -30,6 +30,7 @@ public function jsChecked() protected function init(): void { parent::init(); + if (!$this->class) { $this->class = 'cb_' . $this->shortName; } diff --git a/src/Table/Column/FilterModel.php b/src/Table/Column/FilterModel.php index c52fcd7cfe..15b8621517 100644 --- a/src/Table/Column/FilterModel.php +++ b/src/Table/Column/FilterModel.php @@ -87,6 +87,7 @@ public static function factoryType(App $app, Field $field): self protected function init(): void { parent::init(); + $this->op = $this->addField('op', ['ui' => ['caption' => '']]); if (!$this->noValueField) { diff --git a/src/Table/Column/KeyValue.php b/src/Table/Column/KeyValue.php index db8fac2c53..e73ba407aa 100644 --- a/src/Table/Column/KeyValue.php +++ b/src/Table/Column/KeyValue.php @@ -46,11 +46,6 @@ class KeyValue extends Table\Column { public $values = []; - protected function init(): void - { - parent::init(); - } - /** * @param Field|null $field * diff --git a/src/UserAction/ConfirmationExecutor.php b/src/UserAction/ConfirmationExecutor.php index ac4e41c829..9c11c4011d 100644 --- a/src/UserAction/ConfirmationExecutor.php +++ b/src/UserAction/ConfirmationExecutor.php @@ -52,6 +52,7 @@ class ConfirmationExecutor extends Modal implements JsExecutorInterface protected function init(): void { parent::init(); + $this->observeChanges(); $this->addClass($this->size); } diff --git a/src/UserAction/ExecutorFactory.php b/src/UserAction/ExecutorFactory.php index 68dd0ee3bd..dade6df175 100644 --- a/src/UserAction/ExecutorFactory.php +++ b/src/UserAction/ExecutorFactory.php @@ -258,7 +258,9 @@ protected function getAddActionCaption(UserAction $action): string return 'Add' . ($action->getModel()->caption ? ' ' . $action->getModel()->caption : ''); } - // Generate id for a model user action. + /** + * Generate id for a model user action. + */ protected function getModelId(UserAction $action): string { return strtolower(str_replace(' ', '_', $action->getModel()->getModelCaption())); diff --git a/src/UserAction/ModalExecutor.php b/src/UserAction/ModalExecutor.php index 64c16a03fb..4d583a41a1 100644 --- a/src/UserAction/ModalExecutor.php +++ b/src/UserAction/ModalExecutor.php @@ -39,6 +39,7 @@ class ModalExecutor extends Modal implements JsExecutorInterface protected function init(): void { parent::init(); + $this->initExecutor(); } diff --git a/src/UserAction/PanelExecutor.php b/src/UserAction/PanelExecutor.php index d6dc2bbb44..3176dd05a5 100644 --- a/src/UserAction/PanelExecutor.php +++ b/src/UserAction/PanelExecutor.php @@ -42,6 +42,7 @@ class PanelExecutor extends Right implements JsExecutorInterface protected function init(): void { parent::init(); + $this->initExecutor(); } diff --git a/src/UserAction/VpExecutor.php b/src/UserAction/VpExecutor.php index 1231a4d634..fc1235f7a1 100644 --- a/src/UserAction/VpExecutor.php +++ b/src/UserAction/VpExecutor.php @@ -47,6 +47,7 @@ class VpExecutor extends View implements JsExecutorInterface protected function init(): void { parent::init(); + $this->initExecutor(); } diff --git a/src/View.php b/src/View.php index d73db1547e..ec11d3915c 100644 --- a/src/View.php +++ b/src/View.php @@ -215,6 +215,7 @@ protected function init(): void { $addLater = $this->_addLater; $this->_addLater = []; + parent::init(); if ($this->region && !$this->template && !$this->defaultTemplate && $this->issetOwner() && $this->getOwner()->template) {