简体   繁体   English

ValidateNumber本地化i Flow

[英]ValidateNumber localization i Flow

Am I using this right? 我使用这个权利吗? For a float value. 对于浮点值。 12,12 get rejected, 12.12 does not. 12,12被拒绝, 12.12不接受。 I want the opposite to be true. 我希望事实相反。

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

Reference here (but no usage example ><) 此处参考(但没有使用示例> <)

Actually validation is too late. 实际验证为时已晚。 What you want is map a string 12,12 to a float value 12.12 . 您想要的是将字符串12,12映射到浮点值12.12 This comes before validation. 这是在验证之前。 So you need to configure the PropertyMapper. 因此,您需要配置PropertyMapper。 See comments in the \\TYPO3\\Flow\\Property\\TypeConverter\\FloatConverter which are pretty extensive. 请参阅\\TYPO3\\Flow\\Property\\TypeConverter\\FloatConverter中的注释,这些注释非常广泛。

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. 对于将格式12,1212.12都接受为浮点数12.12的其他问题,您可能需要编写自己的FloatConverter来检查是否存在逗号并进行两次转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM