I have a masked input like this:
<?= $form->field($model, 'ip')->widget(\yii\widgets\MaskedInput::className(),[
'clientOptions' => [
'alias' => 'ip',
'groupSeparator' => '.',
'autoGroup' => true,
],
]);
?>
and I have a kartik gridview with editable field (ip) in my index file:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'ip',
],
'objectID',
'ownerID',
'subnetID',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
How can I set masked input when user update ip field in gridview? And also how should I use dropdownlist to update fields?
You can use MaskedInput widget for example in the "filter" context
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'ip',
'filter'=> MaskedInput::widget([
'name'=>'MyFilterModelName[ip]',
'clientOptions' => [
'alias' => 'ip',
],
]);
],
'objectID',
'ownerID',
'subnetID',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
otherwise, as a row field you can pass the MaskedInput widget as result of an anonymous function:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'ip',
'value' => function($model) {
return MaskedInput::widget([
'name' => 'ip_' . $model->id,
'value' => $model->ip,
'clientOptions' => [
'alias' => 'ip',
],
])
},
],
'objectID',
'ownerID',
'subnetID',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
InputMask is integrated with Yii2 and is highly configurable. Se here and here for tips&tricks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With