Skip to content

Commit

Permalink
Remove default html type from Input control class (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 22, 2023
1 parent 4394d1e commit 1408608
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions demos/basic/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion docs/form-control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
7 changes: 3 additions & 4 deletions src/Form/Control/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 1 addition & 4 deletions src/Form/Control/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions src/Form/Control/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

class Line extends Input
{
public string $inputType = 'text';
}
2 changes: 2 additions & 0 deletions src/Form/Control/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Money extends Input
{
public string $inputType = 'text';

public function getValue()
{
$res = parent::getValue();
Expand Down
2 changes: 1 addition & 1 deletion src/Js/JsBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= ';';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Js/JsChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 1408608

Please sign in to comment.