Commit c747875b authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #4542 - Format number according to decimalFormat on Form load

parent 056830cd
...@@ -1110,6 +1110,11 @@ abstract class AbstractBuildForm { ...@@ -1110,6 +1110,11 @@ abstract class AbstractBuildForm {
$value = ''; $value = '';
} }
if ($formElement[FE_DECIMAL_FORMAT] !== '') {
$decimalScale = explode(',', $formElement[FE_DECIMAL_FORMAT])[1]; // scale: Nachkommastellen
$value = number_format($value, $decimalScale, '.', '');
}
$formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea); $formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea);
if ($flagTextarea) { if ($flagTextarea) {
$htmlTag = '<textarea'; $htmlTag = '<textarea';
......
...@@ -70,6 +70,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -70,6 +70,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
public function testBuildInput() { public function testBuildInput() {
$form = array(); $form = array();
$formElement = array(); $formElement = array();
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$json = array(); $json = array();
$this->templateFormNFormElement($form, $formElement); $this->templateFormNFormElement($form, $formElement);
......
...@@ -84,24 +84,25 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase { ...@@ -84,24 +84,25 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALLBUT), "SANITIZE_ALLBUT fails"); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALLBUT), "SANITIZE_ALLBUT fails");
# Check Decimal Format # Check Decimal Format
$msg = "Sanitize: Decimal Format check fails";
$val = '123.45'; $val = '123.45';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'), $msg);
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'), $msg);
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'), $msg);
$val = '-123.45'; $val = '-123.45';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'), $msg);
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'), $msg);
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'), $msg);
$val = 'a.00'; $val = 'a.00';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$val = '-0.1e9'; $val = '-0.1e9';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$val = '-4'; $val = '-4';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$val = '.42'; $val = '.42';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2')); $this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment