Skip to content

Commit

Permalink
API Use "number" HTML5 type for NumericField by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Harvey committed Aug 4, 2014
1 parent fc1eb1c commit 1759d5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/en/changelogs/3.2.0.md
Expand Up @@ -6,6 +6,7 @@

* Minimum PHP version raised to 5.3.3
* DataObject::validate() method visibility changed to public
* NumericField now uses HTML5 "number" type instead of "text"
* UploadField "Select from files" shows files in all folders by default
* UploadField won't display an overwrite warning unless Upload:replaceFile is true
* HtmlEditorField no longer substitutes `<blockquote />` for indented text
Expand Down
7 changes: 7 additions & 0 deletions forms/NumericField.php
Expand Up @@ -13,6 +13,13 @@ public function Type() {
return 'numeric text';
}

public function getAttributes() {
return array_merge(parent::getAttributes(), array(
'type' => 'number',
'step' => 'any' // allows entering float/decimal numbers like "1.2" instead of just integers
));
}

public function validate($validator) {
if(!$this->value && !$validator->fieldIsRequired($this->name)) {
return true;
Expand Down
11 changes: 10 additions & 1 deletion tests/forms/NumericFieldTest.php
Expand Up @@ -34,4 +34,13 @@ public function testValidator() {
$field->setValue('12.00');
$this->assertFalse($field->validate($validator));
}
}

public function testNumberTypeOnInputHtml() {
$field = new NumericField('Number');

$html = $field->Field();
$this->assertContains('type="number"', $html, 'number type set');
$this->assertContains('step="any"', $html, 'step value set to any');
}

}

0 comments on commit 1759d5d

Please sign in to comment.