Yii2屏蔽的输入日期时间,dd-mm-yyyy hh:mm

时间:2018-12-11 05:33:51

标签: date datetime yii2

我使用Yii2 maskedInput将日期时间格式转换为表单。

<?php
    echo $form->field($modelIsoTanksDeliveryOrder, "open_stack", [
        'template' => '{input}{error}{hint}'
    ])
        ->widget(\yii\widgets\MaskedInput::className(), [
                'clientOptions' => [
                    'alias' => 'datetime',
                ],
                'options' => [
                    'placeholder' => '__-__-____ __:__'
                ]
            ]
        )->label(false)
?>

我正在尝试将“ datetime”掩码的行为更改为使用dd-mm-yyyy hh:mm而不是dd / mm / yyyy hh:mm。

我在JS RobinHerbots上发现了配置 但是仍然失败了

->widget(\yii\widgets\MaskedInput::className(), [
        'clientOptions' => [
            'alias' => 'dd-mm-yyyy',
            'separator' => "-",
        ],
        'mask' => '1-2-y h:s',
        'options' => [
            'placeholder' => '__-__-____ __:__'
        ]
    ]
)

1 个答案:

答案 0 :(得分:1)

您需要为alias使用placeholder以及separatorclientOptions选项,如下所示

<?php echo

    $form->field(
        $modelIsoTanksDeliveryOrder, "open_stack", [
            'template' => '{input}{error}{hint}'
        ]
    )->widget(
        \yii\widgets\MaskedInput::class, [
            'mask' => "1-2-y h:s",
            'clientOptions' => [
                'alias' => 'datetime',
                "placeholder" => "dd-mm-yyyy hh:mm",
                "separator" => "-"
            ]
        ]
    );

?>

详细了解他的thread