doufu8887 2017-02-14 07:30
浏览 66

如何解决yii2中动态表单上的select 2 widget错误

This is what the error looks like:

enter image description here

The error only exists when I use select 2 on dynamic form widget by wbrangca. And also same problem occurs for depdropdown.

Console error:

jquery.js:1468 Uncaught Error: Syntax error, unrecognized expression: #salesqty-{$i}-catagory_id
at Function.Sizzle.error (jquery.js:1468)
at Sizzle.tokenize (jquery.js:2125)
at Sizzle.select (jquery.js:2546)
at Function.Sizzle [as find] (jquery.js:869)
at jQuery.fn.init.find (jquery.js:2792)
at jQuery.fn.init (jquery.js:2909)
at jQuery (jquery.js:75)
at HTMLDocument.<anonymous> (create:809)
at fire (jquery.js:3187)
at Object.fireWith [as resolveWith] (jquery.js:3317)
yii2-dynamic-form.js:90 Uncaught TypeError: Cannot read property 'settings' of undefined
at _parseTemplate (yii2-dynamic-form.js:90)
at HTMLFormElement.<anonymous> (yii2-dynamic-form.js:37)
at Function.each (jquery.js:365)
at jQuery.fn.init.each (jquery.js:137)
at jQuery.fn.init.init (yii2-dynamic-form.js:36)
at jQuery.fn.init.$.fn.yiiDynamicForm (yii2-dynamic-form.js:19)
at create:826
at dispatch (jquery.js:4737)
at elemData.handle (jquery.js:4549)

And the javascript looks like:

var $hasSelect2 = $(widgetOptionsRoot.widgetItem).find('[data-krajee-select2]');
if ($hasSelect2.length > 0) {
    $hasSelect2.each(function() {
        var id = $(this).attr('id');
        var configSelect2 = eval($(this).attr('data-krajee-select2'));

        if ($(this).data('select2')) {
            $(this).select2('destroy');
        }

        var configDepdrop = $(this).data('depdrop');
        if (configDepdrop) {
            configDepdrop = $.extend(true, {}, configDepdrop);
            $(this).removeData().off();
            $(this).unbind();
            _restoreKrajeeDepdrop($(this));
        }
        var s2LoadingFunc = typeof initSelect2Loading != 'undefined' ? initSelect2Loading : initS2Loading;
        var s2OpenFunc = typeof initSelect2DropStyle != 'undefined' ? initSelect2Loading : initS2Loading;
        $.when($('#' + id).select2(configSelect2)).done(s2LoadingFunc(id, '.select2-container--krajee'));

        var kvClose = 'kv_close_' + id.replace(/\-/g, '_');

        $('#' + id).on('select2:opening', function(ev) {
            s2OpenFunc(id, kvClose, ev);
        });

        $('#' + id).on('select2:unselect', function() {
            window[kvClose] = true;
        });

       if (configDepdrop) {
            var loadingText = (configDepdrop.loadingText) ? configDepdrop.loadingText : 'Loading ...';
            initDepdropS2(id, loadingText);
        }
    });
} 

If I don't use the select 2 widget there will be no error on console.

  • 写回答

1条回答 默认 最新

  • dongshuogai2343 2018-01-03 21:32
    关注

    if you still need... Check for the use of single

    '

    instead of

    "

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP