Yii Framework Forum

Masked Input


(Sequeira Jorgepaulo) #1

Hi, I’m trying to establish a masked input for money. This code almost works. The only problem is that when saving to the database the decimal part is forgotten. Ex: 12,76 is stored as 12.




            <?= $form->field($model, 'valor')->widget(\yii\widgets\MaskedInput::className(), [

            'clientOptions' => [

                'alias' => 'decimal',

                'radixPoint' => ',',

                'digits' => 2,

                'groupSeparator' => '.',

            ],

            ]) ; ?>



This is probably a stupid little thing but I can’t figure out what’s happening.

Can anyone please help?


(Fosales) #2

Hi Jorge,

You need to replace the decimal separator (comma per point). In the model`s class, you can do this through the method "onBeforeSave()".