Answer the question
In order to leave comments, you need to log in
How to convert value in validation?
Such a question, I have a widget with a MaskedInput currency format. There you drive in, let's say 101111120, in the input 10 111 120 '. Only when you send the form to save the value field writes the value must be a number. From the integer format, I switched to doulbe, but I still didn’t solve
the problem in the view
<?= $form->field($model, 'oplata')->widget(MaskedInput::className(), [
'clientOptions' => [
'alias' => 'decimal',
'groupSeparator' => ' ',
'autoGroup' => true,
],
'options' => ['placeholder' => 'Cтоимость', 'class' => 'inputWidget-form'],
])->label(false) ?>
public function rules()
{
return [
[[ 'oplata'], 'number'],
];
}
Answer the question
In order to leave comments, you need to log in
As soon as spaces appear in a string, it can no longer be a number, it's a string.
['oplata', 'filter', 'filter' => function ($value) {
return str_replace(" ", "", $value);
}],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question