I have a number attribute
[['UnitPrice'], 'number'],
and I’m trying to format it using the MaskedInput widget
$form->field($model, 'UnitPrice',
[
'template' => '<div class="col-sm-2">{label}</div><div class="col-sm-2">{input}{error}</div>',
'labelOptions' => [
'class'=>'control-label'
]
])
->textInput(['maxlength' => true])
->widget(\yii\widgets\MaskedInput::className(), [
'options' => ['class' => 'form-control text-right', 'onchange' => 'js:recalcSubTotal();'],
'clientOptions' => [
'alias' => 'decimal',
'digits' => 2,
'digitsOptional' => false,
'radixPoint' => '.',
'groupSeparator' => ',',
'autoGroup' => true,
'removeMaskOnSubmit' => true,
'allowMinus' => false,
'min' => '0',
'max' => '99999.99',
// 'numericInput' => true,
],
]
);
My issue is that when I input a number and it gets nicely formatted, Yii2 report an error to the user “Unit Price must be a number.”.
What is the proper way of getting the two to play nice.
Is switching the attribute to String the only answer?