How to disable the nex date picker in update section of Yii2

Hi,
I am using yii2 basic. I have groupdetails CRUD and I am using nex\datepicker\DatePicker extension for a field. I want that this field should not be allowed to edit in update page.

How to achieve this? Waiting for reply.

You can use ActiveRecord::isNewRecord to decide whether the form is used in create or update.

https://www.yiiframework.com/doc/api/2.0/yii-db-baseactiverecord#$isNewRecord-detail

<?php if ($model->isNewRecord) : ?>
// use date picker
<?= DatePicker(...) ?>
<?php else: ?>
// use plain text
<p><?= $model->date; ?> </p>
<?php endif ?>

Or, when you can make use of a property of the date picker widget (something like readOnly or disabled), you could set it according to $model->isNewRecord.

Hi,

For nex date picker there is no disabled option. Only readonly can use. But if readonly use then still the date picker is displayed from which we can edit the date.

<?php if ($model->isNewRecord) : ?>
    <?= $form->field($model, 'FormationDate')->textInput()->widget(
    DatePicker::className(), [
        'addon' => false,
        'readonly'=>true,
		
        'size' => 'sm',
        'clientOptions' => [
            'format' => 'YYYY-MM-DD',
            'stepping' => 30,
        ],
]);?>
<?php else: ?>
<?= $form->field($model, 'FormationDate')->widget(
    DatePicker::className(), [
        'addon' => false,
        'readonly'=>true,
        'size' => 'sm',
        'clientOptions' => [
            'format' => 'YYYY-MM-DD',
            'stepping' => 30,
        ],
]);?>
<?php endif ?>

Since DatePicker is inherited from InputWidget. You can add disabled attribute by passing the options param. like.

'options' => [
    'disabled' => 'disabled',
],

If I include in option disabled=>disabled, then it is working but there are two fields which also uses the date picker. Those two fields are also getting disabled.

<?php if ($model->isNewRecord) : ?>
    <?= $form->field($model, 'FormationDate')->textInput()->widget(
    DatePicker::className(), [
        'addon' => false,
        'readonly'=>true,
        'size' => 'sm',
        'clientOptions' => [
            'format' => 'YYYY-MM-DD',
            //'stepping' => 30,
        ],
]); ?>
<?php else: ?>
<?= $form->field($model, 'FormationDate')->textInput()->widget(
    DatePicker::className(), [
        'addon' => false,
        'readonly'=>true,
        'size' => 'sm',
        'clientOptions' => [
            'format' => 'YYYY-MM-DD',
            //'stepping' => 30,
			'disabled'=>'disabled',
        ],
]); ?>
<?php endif ?>