dongyan1974 2014-02-04 11:24
浏览 32
已采纳

Prestashop - 产品管理员:未调用自动完成

I added a custom field named product_type in Product admin. It works well, but now, I'm trying to add an autocomplete to this field.

Here is my code (in \mysite\admin\themes\default\template\controllers\products\informations.tpl)

<td style="padding-bottom:5px;">
    <input size="55" type="text" id="product_type" name="product_type" value="{$product->product_type|escape:html:'UTF-8'}" style="width: 130px; margin-right: 5px;" />
    <script type="text/javascript">
        $(document).ready(function() {
            $('#product_type').autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "ajax.php",
                        dataType: "json",
                        data: { term: request.term, ajaxProductType: 1 },
                        success: function(data) { response(data); }
                    });
                },              
                minLength: 3,
                select: function( event, ui ) {
                    $(this).val(ui.item.value);
                }
            });
        });
    </script>
</td>

When I write in the field, nothing happen. The autocomplete is not called. No error in console. However, when I put an alert() in the document.ready function, it shows. So, why my autocomplete doesn't work?

Version : Prestashop 1.5.6

Thanks in advance for your help

  • 写回答

1条回答 默认 最新

  • dsogx84602 2014-02-07 13:23
    关注

    I finally found the problem. The form was loaded by ajax.

    So, I had to move the script in the file \prestashop\js\admin-products.js and put it inside the function product_tabs['Informations'] (because my field is under the tab Informations). I also changed the autocomplete script as below.

    product_tabs['Informations'] = new function(){
        //... 
        $('#product_type').autocomplete('ajax.php', {
            delay: 100,
            minChars: 1,
            autoFill: true,
            max:255,
            matchContains: true,
            mustMatch:true,
            scroll:false,
            cacheLength:0,
            extraParams: {
                ajaxProductType : 1
            }
        }).result(function(event, item){
            $(this).val(item);
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?