drevls8138 2017-03-02 15:23
浏览 104

Yii2 Kartik TimePicker - 不能在多个模态窗口中使用

I have a page that launches modal windows that include two TimePicker widgets. When opening the first modal, everything works. It can be reopened as well. However, when opening another modal, I get a console error:

Uncaught TypeError: Cannot read property 'apply' of undefined
at HTMLInputElement.eval (eval at globalEval (jquery.js:343), <anonymous>:851:29)
at Function.each (jquery.js:365)
at jQuery.fn.init.each (jquery.js:137)
at jQuery.fn.init.$.fn.timepicker (eval at globalEval (jquery.js:343), <anonymous>:841:21)
at HTMLDocument.eval (eval at globalEval (jquery.js:343), <anonymous>:3:107)
at fire (jquery.js:3187)
at Object.add [as done] (jquery.js:3246)
at jQuery.fn.init.jQuery.fn.ready (jquery.js:3496)
at eval (eval at globalEval (jquery.js:343), <anonymous>:1:18)
at eval (<anonymous>)

Here is the code causing the error:

//TIMEPICKER PLUGIN DEFINITION
$.fn.timepicker = function (option) {
    var args = Array.apply(null, arguments);
    args.shift();
    return this.each(function () {
        var $this = $(this),
            data = $this.data('timepicker'),
            options = typeof option === 'object' && option;

        if (!data) {
            $this.data('timepicker', (data = new Timepicker(this, $.extend({}, $.fn.timepicker.defaults, options, $(this).data()))));
        }

        if (typeof option === 'string') {
            data[option].apply(data, args); // This is the line that causes problems
        }
    });
};

Here is the PHP code for one of the widgets:

<?= $form->field($model, 'TimeEntryStartTime',[
                'showLabels'=>false
                ])->widget(TimePicker::classname(),[
                    'options' => ['placeholder' => 'Enter time...'],
                ]); ?>

Here is the javascript that launches the modals (similar for each):

// Modal view for Monday
$('#modalButtonMonday').click(function(){
// get the click of the create button
    $('#modalMonday').modal('show')
        .find('#modalContentMonday')
        .load($(this).attr('value'));
});     
$('#modalMonday').on('hidden.bs.modal', function (e) {
  // reload page when modal closed
  location.reload(true);
});
  • 写回答

1条回答 默认 最新

  • douan8473 2017-03-31 02:17
    关注

    try setting different names in the widget with

    'name'=>timepickerName;

    or in the 'option' html array insert an ids or class for each one, ex. 'id'=>'timepickerId'

    and write another .fn. with the correspondent name or id.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100