Skip to content

Commit

Permalink
Fix '0' instead of '' default value for Lookup (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Aug 19, 2022
1 parent 95580a9 commit 79c5f61
Show file tree
Hide file tree
Showing 32 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions demos/_includes/Demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions demos/_includes/SomeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
1 change: 1 addition & 0 deletions demos/basic/columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
protected function init(): void
{
parent::init();

\Atk4\Ui\Table::addTo($this, ['header' => false])
->setSource(['One', 'Two', 'Three', 'Four']);
}
Expand Down
1 change: 1 addition & 0 deletions demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]);
Expand Down
5 changes: 5 additions & 0 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -403,6 +405,7 @@ class Category extends ModelWithPrefixedFields
protected function init(): void
{
parent::init();

$this->addField($this->fieldName()->name);

$this->hasMany($this->fieldName()->SubCategories, [
Expand All @@ -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, [
Expand All @@ -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, [
Expand Down
1 change: 1 addition & 0 deletions docs/form-control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
1 change: 1 addition & 0 deletions docs/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']]);
Expand Down
1 change: 1 addition & 0 deletions docs/multiline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]]);
Expand Down
1 change: 1 addition & 0 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CardDeck extends View
protected function init(): void
{
parent::init();

$this->container = $this->add($this->container);

if ($this->menu !== false) {
Expand Down
1 change: 1 addition & 0 deletions src/CardSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CardSection extends View
protected function init(): void
{
parent::init();

$this->addClass('content');
}

Expand Down
1 change: 1 addition & 0 deletions src/Component/InlineEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 1 addition & 0 deletions src/HelloWorld.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HelloWorld extends View
protected function init(): void
{
parent::init();

$this->set('Content', 'Hello World');
}
}
1 change: 1 addition & 0 deletions src/JsSortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class JsSortable extends JsCallback
protected function init(): void
{
parent::init();

if (!$this->view) {
$this->view = $this->getOwner();
}
Expand Down
1 change: 1 addition & 0 deletions src/LoremIpsum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Modal extends View
protected function init(): void
{
parent::init();

$this->getApp()->registerPortals($this);
}

Expand Down
1 change: 1 addition & 0 deletions src/Panel/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions src/Panel/Right.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions src/Table/Column/ActionButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ActionButtons extends Table\Column
protected function init(): void
{
parent::init();

$this->addClass('right aligned');
}

Expand Down
5 changes: 0 additions & 5 deletions src/Table/Column/ActionMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions src/Table/Column/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function jsChecked()
protected function init(): void
{
parent::init();

if (!$this->class) {
$this->class = 'cb_' . $this->shortName;
}
Expand Down
1 change: 1 addition & 0 deletions src/Table/Column/FilterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/Table/Column/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ class KeyValue extends Table\Column
{
public $values = [];

protected function init(): void
{
parent::init();
}

/**
* @param Field|null $field
*
Expand Down
1 change: 1 addition & 0 deletions src/UserAction/ConfirmationExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ConfirmationExecutor extends Modal implements JsExecutorInterface
protected function init(): void
{
parent::init();

$this->observeChanges();
$this->addClass($this->size);
}
Expand Down
4 changes: 3 additions & 1 deletion src/UserAction/ExecutorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
1 change: 1 addition & 0 deletions src/UserAction/ModalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ModalExecutor extends Modal implements JsExecutorInterface
protected function init(): void
{
parent::init();

$this->initExecutor();
}

Expand Down
1 change: 1 addition & 0 deletions src/UserAction/PanelExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PanelExecutor extends Right implements JsExecutorInterface
protected function init(): void
{
parent::init();

$this->initExecutor();
}

Expand Down
1 change: 1 addition & 0 deletions src/UserAction/VpExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VpExecutor extends View implements JsExecutorInterface
protected function init(): void
{
parent::init();

$this->initExecutor();
}

Expand Down
1 change: 1 addition & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 79c5f61

Please sign in to comment.