Phone number mask is not working

I have a form like this


When pressed on “add more contacts” more phone number field will be added

I used an array for declaring the model. Here values will save perfectly. But contact mask and validation not working for me

Form field is like this
<?=$form->field ( $model, ‘contact[]’
, [‘options’=>[‘class’=>’’]
, ‘wrapperOptions’=>[‘class’=>’’]
])->widget ( \yii\widgets\MaskedInput::className (),
[ ‘name’ => ‘input-1’,‘mask’ => ‘(999)-999-9999’
])->textInput([‘placeholder’ => ‘(999)-999-9999’])->label(false);
?>

Since the mask is not working I added a placeholder here. Then Tried to add a validation like below

My validation code like this

[‘more_contact’, ‘each’, ‘rule’ => [‘integer’,‘min’=>10,‘max’=>‘12’]],

But this also not working for me.How can I solve this problem?

This mask form field with the mask, its drawing through ajax?
Then this is a possible solution: Validation in form fields rendered via Ajax - #2 by hrnair

If the mask won’t work drawing the field directly from PHP, I would recommend you to check your browsers console for JS issues.

As for the backend, always good to validate on backend.
Just keep in mind that this phone data will come as string, not integer, in the request.
So you will have to validate for a string with a given pattern (Yii2 Core Validators - match) or do some custom validator for that, like those from Kartik.

A good way to pick this is using XDebug and checking what is happening on each step inside your action.