Hi all,
I want to auto populate fields (inspection_date & date_dismantled) with DATE or return NULL depending on status selected from status_id dropdown options.
Here’s my _form:
<div class="row">
<?php echo $form->labelEx($model,'date_inspected'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'attribute' => 'date_inspected',
'model' => $model,
// additional javascript options for the date picker plugin
'options' => array(
'autoSize' => true,
'showAnim' => 'slideDown',
'showOn' => 'button',
'changeMonth' => true,
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'style' => 'height:20px;',
),
));?>
<?php echo $form->error($model,'date_inspected'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'status_id'); ?>
<?php echo $form->dropDownList($model,'status_id', $model->getStatusOptions(), array('prompt'=>'Select Status')); ?>
<?php echo $form->error($model,'status_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'inspection_date'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'attribute' => 'inspection_date',
'model' => $model,
// additional javascript options for the date picker plugin
'options' => array(
'autoSize' => true,
'showAnim' => 'slideDown',
'showOn' => 'button',
'changeMonth' => true,
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'style' => 'height:20px;',
),
));?>
<?php echo $form->error($model,'inspection_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date_dismantled'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'attribute' => 'date_dismantled',
'model' => $model,
// additional javascript options for the date picker plugin
'options' => array(
'autoSize' => true,
'showAnim' => 'slideDown',
'showOn' => 'button',
'changeMonth' => true,
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'style' => 'height:20px;',
),
));?>
<?php echo $form->error($model,'date_dismantled'); ?>
</div>
status_id has 3 options: "Green Tag, Red Tag and Dismantled".
What I wish to happen is when I choose “Green Tag or Red Tag” the inspection_date field will be populated by today’s date +7days and date_dismantled field will remain Null (something like: $model->inspection_date = date(‘Y-m-d’, strtotime(’+7 days ')); $model->date_dismantled = Null;). But when I choose “Dismantled”, inspection_date will return Null and date_dismantled will be populated with today’s date (something like: $model->inspection_date = Null; $model->date_dismantled = date(‘Y-m-d’).
By the way date_inspected & inspection_date fields are auto fill with DATES from the InspectionController upon initializing the form.
Note: inspection_date is labeled as Next Inspection Due on the attached image.
public function actionCreate()
{
$model=new Inspection;
$model->date_inspected = date('Y-m-d');
$model->inspection_date = date('Y-m-d', strtotime('+7 days '));...
But I want different approach and changes are happening immediately after selecting status.
Any idea how to achieve it and please provide an example. Thanks in Advance.