Merge pull request #3361 from halkyon/number_type_numericfield

API Use "number" HTML5 type for NumericField by default
This commit is contained in:
Hamish Friedlander 2014-08-04 16:02:13 +12:00
commit ca68f585cc
3 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -13,6 +13,13 @@ class NumericField extends TextField {
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;

View File

@ -34,4 +34,13 @@ class NumericFieldTest extends SapphireTest {
$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');
}
}