Skip to content

Commit

Permalink
There is no "attr" for simple inputs
Browse files Browse the repository at this point in the history
Add test on type != text
  • Loading branch information
trasher committed Dec 14, 2017
1 parent d7dc61c commit efded92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions inc/commondropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,8 @@ function showForm($ID, $options = []) {
} else {
echo Html::input(
$field['name'], [
'attrs' => [
'type' => 'number'
] + $params]
] + $params
);
}
break;
Expand Down
6 changes: 3 additions & 3 deletions inc/html.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4521,9 +4521,9 @@ static function hidden($fieldName, $options = []) {
**/
static function input($fieldName, $options = []) {
$type = 'text';
if (isset($options['attrs']) && isset($options['attrs']['type'])) {
$type = $options['attrs']['type'];
unset($options['attrs']['type']);
if (isset($options['type'])) {
$type = $options['type'];
unset($options['type']);
}
return sprintf('<input type="%1$s" name="%2$s" %3$s />',
$type, Html::cleanInputText($fieldName), Html::parseAttributes($options));
Expand Down
9 changes: 9 additions & 0 deletions tests/units/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,5 +880,14 @@ public function testInput() {
];
$expected = '<input type="text" name="in_put" value="myval" class="a_class" data-id="12" />';
$this->string(\Html::input($name, $options))->isIdenticalTo($expected);

$options = [
'type' => 'number',
'min' => '10',
'value' => 'myval',
];
$expected = '<input type="number" name="in_put" min="10" value="myval" />';
$this->string(\Html::input($name, $options))->isIdenticalTo($expected);

}
}

0 comments on commit efded92

Please sign in to comment.