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 {
$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);
if ($flagTextarea) {
$htmlTag = '<textarea';
......
......@@ -70,6 +70,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
public function testBuildInput() {
$form = array();
$formElement = array();
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$json = array();
$this->templateFormNFormElement($form, $formElement);
......
......@@ -84,24 +84,25 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALLBUT), "SANITIZE_ALLBUT fails");
# Check Decimal Format
$msg = "Sanitize: Decimal Format check fails";
$val = '123.45';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'));
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'));
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'));
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'));
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'), $msg);
$this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'), $msg);
$this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'), $msg);
$val = '-123.45';
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'));
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'));
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'));
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'));
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '10,3'), $msg);
$this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '4,2'), $msg);
$this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,1'), $msg);
$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';
$this->assertEquals('', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'));
$this->assertEquals('!!all!!', Sanitize::sanitize($val, SANITIZE_ALLOW_ALL, '', '5,2'), $msg);
$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';
$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