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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算