Class yii\widgets\MaskedInput
MaskedInput generates a masked text input.
MaskedInput is similar to yii\helpers\Html::textInput() except that an input mask will be used to force users to enter properly formatted data, such as phone numbers, social security numbers.
Yii2 MaskedInput to collect phone numbers:
echo MaskedInput::widget([
'name' => 'phone',
'mask' => '999-999-9999',
]);
You can also use this widget in an yii\widgets\ActiveForm using the widget() method, for example like this:
<?= $form->field($model, 'from_date')->widget(\yii\widgets\MaskedInput::className(), [
'mask' => '999-999-9999',
]) ?>
Demonstration and usage examples for the Yii 2.0 Masked Input widget.
Masked input to collect date from users
More Masked Inputs
Code paste to your view
use yii\widgets\MaskedInput;
- echo MaskedInput::widget([
- 'name' => 'input-31',
- 'clientOptions' => ['alias' => 'date']
- ]);
Example
Masked date input use in active form.
<?= $form->field($model, 'date_of_birth')->widget(\yii\widgets\MaskedInput::className(), [
'name' => 'input-31',
'clientOptions' => ['alias' => 'dd-mm-yyyy'],
]) ?>
Retype your date format in 'clientOptions' => ['alias' => 'dd-mm-yyyy']
Masked Amount input
- echo MaskedInput::widget([
- 'name' => 'input-33',
- 'clientOptions' => [
- 'alias' => 'decimal',
- 'groupSeparator' => ',',
- 'autoGroup' => true
- ],
- ]);
Masked URL input
- echo MaskedInput::widget([
- 'name' => 'input-35',
- 'clientOptions' => [
- 'alias' => 'url',
- ],
- ]);
Masked Email input
- echo MaskedInput::widget([
- 'name' => 'input-36',
- 'clientOptions' => [
- 'alias' => 'email'
- ],
- ]);
Masked Other Phone | US Phone input
- echo MaskedInput::widget([
- 'name' => 'input-5',
- 'mask' => ['99-999-9999', '999-999-9999']
- ]);
More
Yii2 Bootstrap DatePicker Widget for Yii2
/yii2-date-picker-widget
Related Links
No comments:
Post a Comment