Skip to content

Commit

Permalink
Fix #109, fix #117: Add specialized class for input tag with type `Ra…
Browse files Browse the repository at this point in the history
…nge` and methods `Html::range()`, `Input::range()`
  • Loading branch information
vjik committed Apr 27, 2022
1 parent f742e12 commit db13523
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,7 +6,8 @@
- New #105: Add specialized class `File` for an input tag with type `file` and methods `Html::file()` and
`Input::fileControl()` (vjik)
- New #109: Add class for tag `Datalist` and method `Html::datalist()` (vjik)
- New #109: Add specialized class for input tag with type `Range` and methods `Html::range()`, `Input::range()` (vjik)
- New #109, #117: Add specialized class for input tag with type `Range` and methods `Html::range()`,
`Input::range()` (vjik)
- New #113: Add class for tag `Legend`, class for tag `Fieldset`, methods `Html::legend()` and `Html::fieldset()` (vjik)
- New #111: Add widget `ButtonGroup` (vjik)
- New #111: Add method `Tag::unionAttributes()` that available for all tags (vjik)
Expand Down
15 changes: 12 additions & 3 deletions src/Tag/Input/File.php
Expand Up @@ -14,14 +14,22 @@
final class File extends InputTag
{
private ?string $uncheckValue = null;
private array $uncheckInputTagAttributes = [];

/**
* @param bool|float|int|string|Stringable|null $value
*/
public function uncheckValue($value): self
{
$new = clone $this;
$new->uncheckValue = $value === null ? null : (string)$value;
$new->uncheckValue = $value === null ? null : (string) $value;
return $new;
}

public function uncheckInputTagAttributes(array $attributes): self
{
$new = clone $this;
$new->uncheckInputTagAttributes = $attributes;
return $new;
}

Expand All @@ -44,7 +52,7 @@ public function accept(?string $value): self
*
* @param bool $multiple Whether to allow selecting multiple files.
*/
public function multiple(?bool $multiple = true): self
public function multiple(bool $multiple = true): self
{
$new = clone $this;
$new->attributes['multiple'] = $multiple;
Expand Down Expand Up @@ -74,7 +82,8 @@ private function renderUncheckInput(): string

$input = Html::hiddenInput(
Html::getNonArrayableName($name),
$this->uncheckValue
$this->uncheckValue,
$this->uncheckInputTagAttributes
);

// Make sure disabled input is not sending any value.
Expand Down
20 changes: 16 additions & 4 deletions tests/common/Tag/Input/FileTest.php
Expand Up @@ -68,6 +68,22 @@ public function testUncheckValueForm(): void
);
}

public function testUncheckInputTagAttributes(): void
{
$result = File::tag()
->name('avatar')
->uncheckValue(7)
->uncheckInputTagAttributes(['id' => 'FileHidden', 'data-key' => '100'])
->form('post')
->render();

$this->assertSame(
'<input type="hidden" id="FileHidden" name="avatar" value="7" form="post" data-key="100">' .
'<input type="file" name="avatar" form="post">',
$result
);
}

public function dataAccept(): array
{
return [
Expand Down Expand Up @@ -96,10 +112,6 @@ public function testAccept(string $expected, ?string $accept): void
public function dataMultiple(): array
{
return [
[
'<input type="file" name="avatar">',
null,
],
[
'<input type="file" name="avatar" multiple>',
true,
Expand Down

0 comments on commit db13523

Please sign in to comment.