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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同