Reputation: 7404
I am using Yii bootstraps datepickerRow : Check this
I want my end_date depending on start_date. i.e. end_date should be greater than start date. I've spent couple of hours on google to check whether any in-built solution available for it but didn't found any solution. Then after I written my own js code which's I think perfectly fine but its not working.
I've already achieved this thing with Cjuidatepicker and its booming.
Check my working code for yii cjuidatepicker
But I don't know why its not working for yii bootstrap datepickerRow.
Any help would be appreciated.
Following is my code:
<?php
echo $form->datepickerRow(
$identitycard, 'date_of_issue', array(
'onChange' => 'setEndDate("passport_date_of_expiry", this)',
'class' => "input-small",
'labelOptions' => array('label' => 'Date of Issue <span class="required">*</span>'),
'value' => $passportArr['date_of_issue'],
'name' => 'passport[date_of_issue]',
'readonly' => true,
'options' => array(
'autoclose' => true,
'showAnim' => 'fold',
'format' => 'yyyy-mm-dd',
'endDate' => '-infinity'
),
'prepend' => '<i class="icon icon-calendar"></i>',
'hint' => 'yyyy-mm-dd'
)
);
echo $form->datepickerRow(
$identitycard, 'date_of_expiry', array(
'class' => "input-small",
'labelOptions' => array('label' => 'Date of Expiry <span class="required">*</span>'),
'value' => $passportArr['date_of_expiry'],
'name' => 'passport[date_of_expiry]',
'readonly' => true,
'options' => array(
'autoclose' => true,
'showAnim' => 'fold',
'format' => 'yyyy-mm-dd',
),
'prepend' => '<i class="icon icon-calendar"></i>',
'hint' => 'yyyy-mm-dd'
)
);
?>
// JS code
function setEndDate(id, date) {
var selectedDate = $(date).val();
$("#" + id).datepicker({
startDate: selectedDate,
format: "yyyy-mm-dd"
});
}
Upvotes: 0
Views: 1532
Reputation: 2684
In your js function setEndDate
, second parameter date
is not jQuery element (this
in your parameter in datepickerRow). It can't be read with jQuery selector.
In your function setEndDate
you can read input value as date.value;
instead $(date).val();
EDIT:
setEndDate
function should work with this changes (refer to plugin docs related in source code of yiibooster, for example in my yii-booster installation : protected/components/bootstrap/assets/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js ):
function setEndDate(id, date) {
$("#" + id).val(date.value);
$("#" + id).datepicker('setStartDate' , date.value);
}
Upvotes: 1