mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3361 from halkyon/number_type_numericfield
API Use "number" HTML5 type for NumericField by default
This commit is contained in:
commit
ca68f585cc
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user