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

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上