yii2
Yii2 calendario de consultas para el campo de texto
Buscar..
Agregue calendario de jquery para un campo de texto con el máximo como fecha actual
Si queremos mostrar un calendario jquery para el usuario final que puede elegir la fecha máxima como la fecha actual en el calendario. El siguiente código será útil para este escenario.
<?php
use yii\jui\DatePicker;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(['id' => 'profile-form']); ?>
.....
<?= $form->field($model, 'date_of_birth')->widget(DatePicker::classname(), ['dateFormat' => 'php:M d, Y', 'options' => ['readonly' => true], 'clientOptions' => [ 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '1980:'.date('Y'), 'maxDate' => '+0d']]) ?>
.....
<?php ActiveForm::end(); ?>
Añadir calendario jquery para un campo de texto con fecha mínima
Para algunos formularios que desea visualizar, los días de los días futuros / pasados y otros días deben estar deshabilitados, entonces este escenario ayudará.
<?php
use yii\jui\DatePicker;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(['id' => 'profile-form']); ?>
.....
<?php
$day = '+5d'; //if you want to display +5 days from current date means for future days.
#(or)
$day = '-5d'; //if you want to display -5 days from current date means older days.
?>
<?= $form->field($model, 'date_of_birth')->widget(DatePicker::classname(), ['dateFormat' => 'php:M d, Y', 'options' => ['readonly' => true], 'clientOptions' => [ 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '1980:'.date('Y'), 'maxDate' => $day]]) ?>
.....
<?php ActiveForm::end(); ?>
Añadir calendario jquery con desde fecha y hasta la fecha
Si desea tener el calendario desde la fecha y hasta la fecha y también hasta la fecha, los días del calendario siempre serán mayores que desde el campo de la fecha, entonces el escenario siguiente ayudará.
<?php $form = ActiveForm::begin(['id' => 'profile-form']); ?>
.....
<?= $form->field($model, 'from_date')->widget(DatePicker::classname(), ['dateFormat' => 'php:M d, Y', 'options' => ['readonly' => true], 'clientOptions' => [ 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '1980:'.date('Y'), 'onSelect' => new yii\web\JsExpression('function(selected) { var dt = new Date(selected); dt.setDate(dt.getDate() + 1); $("#filter-date-to").datepicker("option", "minDate", dt); }')]]) ?>
<?= $form->field($model, 'to_date')->widget(DatePicker::classname(), ['dateFormat' => 'php:M d, Y', 'options' => ['readonly' => true, 'id' => 'filter-date-to'], 'clientOptions' => [ 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '1980:'.date('Y')]]) ?>
.....
<?php ActiveForm::end(); ?>
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow