From 1408608be12ef2dc113763d02d851b4115146c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 22 Apr 2023 09:31:18 +0200 Subject: [PATCH] Remove default html type from Input control class (#2030) --- demos/basic/menu.php | 4 ++-- docs/form-control.rst | 2 +- src/Form/Control/Calendar.php | 7 +++---- src/Form/Control/Input.php | 5 +---- src/Form/Control/Line.php | 1 + src/Form/Control/Money.php | 2 ++ src/Js/JsBlock.php | 2 +- src/Js/JsChain.php | 2 +- tests/FormTest.php | 5 ++--- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/demos/basic/menu.php b/demos/basic/menu.php index 5c1d79a75e..791a791552 100644 --- a/demos/basic/menu.php +++ b/demos/basic/menu.php @@ -34,12 +34,12 @@ $menu = Menu::addTo($app, ['vertical pointing']); $menu->addItem(['Inbox', 'label' => ['123', 'class.teal left pointing' => true]]); $menu->addItem('Spam'); -Form\Control\Input::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent'); +Form\Control\Line::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent'); $menu = Menu::addTo($app, ['secondary vertical pointing']); $menu->addItem(['Inbox', 'label' => ['123', 'class.teal left pointing' => true]]); $menu->addItem('Spam'); -Form\Control\Input::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent'); +Form\Control\Line::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent'); $menu = Menu::addTo($app, ['vertical']); $group = $menu->addGroup('Products'); $group->addItem('Enterprise'); diff --git a/docs/form-control.rst b/docs/form-control.rst index 3ee07af11e..debce8b0bd 100644 --- a/docs/form-control.rst +++ b/docs/form-control.rst @@ -224,7 +224,7 @@ element. For example, `icon` property: Adds icon into the input form control. Default - `icon` will appear on the right, while `leftIcon` will display icon on the left. -Here are few ways to specify `icon` to an Input:: +Here are few ways to specify `icon` to an Input/Line:: // compact Line::addTo($page, ['icon' => 'search']); diff --git a/src/Form/Control/Calendar.php b/src/Form/Control/Calendar.php index 467356a766..d97ebe31c1 100644 --- a/src/Form/Control/Calendar.php +++ b/src/Form/Control/Calendar.php @@ -10,13 +10,12 @@ use Atk4\Ui\Js\JsExpressionable; use Atk4\Ui\Js\JsFunction; -/** - * Date/Time picker attached to a form control. - */ class Calendar extends Input { + public string $inputType = 'text'; + /** - * Set this to 'date', 'time', 'datetime'. + * @var 'date'|'time'|'datetime' */ public string $type = 'date'; diff --git a/src/Form/Control/Input.php b/src/Form/Control/Input.php index 125ef62bc9..fd8c012dbf 100644 --- a/src/Form/Control/Input.php +++ b/src/Form/Control/Input.php @@ -12,15 +12,12 @@ use Atk4\Ui\UserAction\ExecutorFactory; use Atk4\Ui\UserAction\JsCallbackExecutor; -/** - * Input element for a form control. - */ class Input extends Form\Control { public $ui = 'input'; public $defaultTemplate = 'form/control/input.html'; - public string $inputType = 'text'; + public string $inputType; /** @var string */ public $placeholder = ''; diff --git a/src/Form/Control/Line.php b/src/Form/Control/Line.php index a20e81e405..e9d7181c7e 100644 --- a/src/Form/Control/Line.php +++ b/src/Form/Control/Line.php @@ -6,4 +6,5 @@ class Line extends Input { + public string $inputType = 'text'; } diff --git a/src/Form/Control/Money.php b/src/Form/Control/Money.php index 0b46315afd..b700fd0702 100644 --- a/src/Form/Control/Money.php +++ b/src/Form/Control/Money.php @@ -6,6 +6,8 @@ class Money extends Input { + public string $inputType = 'text'; + public function getValue() { $res = parent::getValue(); diff --git a/src/Js/JsBlock.php b/src/Js/JsBlock.php index 4e90ff5237..ca7e3764de 100644 --- a/src/Js/JsBlock.php +++ b/src/Js/JsBlock.php @@ -61,7 +61,7 @@ public function jsRender(): string $js = $statement->jsRender(); if ($js === '') { continue; - } elseif (!$statement instanceof self && !preg_match('~;\s*$~s', $js)) { + } elseif (!$statement instanceof self && !preg_match('~;\s*$~', $js)) { $js .= ';'; } diff --git a/src/Js/JsChain.php b/src/Js/JsChain.php index 279c2d82b7..7659522543 100644 --- a/src/Js/JsChain.php +++ b/src/Js/JsChain.php @@ -110,7 +110,7 @@ public function jsRender(): string $args = $chain[1]; } - $res .= preg_match('~^(?!\d)\w+$~su', $name) ? '.' . $name : '[' . $this->_jsEncode($name) . ']'; + $res .= preg_match('~^(?!\d)\w+$~Du', $name) ? '.' . $name : '[' . $this->_jsEncode($name) . ']'; if ($args !== null) { $res .= $this->_renderArgs($args); } diff --git a/tests/FormTest.php b/tests/FormTest.php index d9de664856..2797efa882 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -211,17 +211,16 @@ public function testSubmitNonFormFieldError(): void public function testNoDisabledAttrWithHiddenType(): void { - $input = new Form\Control\Input(); + $input = new Form\Control\Line(); $input->disabled = true; $input->readOnly = true; $input->setApp($this->createApp()); static::assertStringContainsString(' disabled="disabled"', $input->render()); static::assertStringContainsString(' readonly="readonly"', $input->render()); - $input = new Form\Control\Input(); + $input = new Form\Control\Hidden(); $input->disabled = true; $input->readOnly = true; - $input->inputType = 'hidden'; $input->setApp($this->createApp()); static::assertStringNotContainsString('disabled', $input->render()); static::assertStringNotContainsString('readonly', $input->render());