flow-framework

ValidateNumber localization i Flow


Am I using this right? For a float value. 12,12 get rejected, 12.12 does not. I want the opposite to be true.

@Flow\Validate(type="Number", options={ "locale"="de_DE" })

Reference here (but no usage example ><)


Solution

  • Actually validation is too late. What you want is map a string 12,12to a float value 12.12. This comes before validation. So you need to configure the PropertyMapper. See comments in the \TYPO3\Flow\Property\TypeConverter\FloatConverter which are pretty extensive.

    Roughly this is what you need:

    protected function initializeCreateAction() {
        $this->arguments['newBid']->getPropertyMappingConfiguration()->
            forProperty('yourPropertyThatShouldBeFloat')->
            setTypeConverterOption('TYPO3\Flow\Property\TypeConverter\FloatConverter', 'locale', 'de');
    }
    

    For the additional question of accepting both formats 12,12 and 12.12 as float 12.12 you probably need to write your own FloatConverter that checks for the existence of a comma and does either of the two conversions.