douzhai7873 2014-09-23 06:19
浏览 45
已采纳

结束日期应大于Yii Bootstrap datepickerRow中的开始日期

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"
    });
}
  • 写回答

1条回答 默认 最新

  • doqw89029 2014-09-26 04:13
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 速帮,学校需要在外上班没空
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义