user2230501
user2230501

Reputation:

jQuery AutoComplete plugin - minLength is taking no effect

The autocomplete is working fine, but it's displaying the auto suggestion box with 1 character, and I would like to change it to display the auto suggestion box only when the input is >=3.

I've been trying to insert 'minLength' option but it is not taking any effetct.

I've tried to modify the sixth line to:

.autocomplete(conf.opts, minLength: 3 || {});


But had no success.


Here's my JS file:

var myEditor;
// AutoComplete FieldType
$.fn.dataTable.Editor.fieldTypes.autoComplete = $.extend(true, {}, $.fn.dataTable.Editor.models.fieldType, {
    "create": function (conf) {
        conf._input = $('<input type="text" id="' + conf.id + '">')
        .autocomplete(conf.opts || {});

        return conf._input[0];
    },

    "get": function (conf) {
        return conf._input.val();
    },

    "set": function (conf, val) {
        conf._input.val(val);
    },

    "enable": function (conf) {
        conf._input.autocomplete('enable');
    },

    "disable": function (conf) {
        conf._input.autocomplete('disable');
    },

    // Non-standard Editor method - custom to this plug-in
    "node": function (conf) {
        return conf._input;
    }
});


$(document).ready(function () {
    myEditor = new $.fn.dataTable.Editor({
        "ajaxUrl": "./php/pTreinamentos.php",
        "domTable": "#example",
        "fields": [{
            "label": "Tema",
            "name": "tema",
            "type": "autoComplete",
            "opts": {
            "source": ['banana']
            }
        }
        ]
    });


    // DataTable
    var oTable = $('#example').dataTable({
        "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sAjaxSource": "./php/pTreinamentos.php",
        "bFilter": true,
        "bAutoWidth": false,
        "iDisplayLength": 20,
        "aoColumns": [{
            "mData": "tema"
            }
        ],
        "oTableTools": {
            "sSwfPath": "../../TableTools/media/swf/copy_csv_xls_pdf.swf",
            "sRowSelect": "single",
            "sPaginationType": "bootstrap",
            "aButtons": [{
                "sExtends": "editor_create",
                "editor": myEditor
                }, {
                "sExtends": "editor_edit",
                "editor": myEditor
                }, {
                "sExtends": "editor_remove",
                "editor": myEditor
                }
            ]
        }
    });

});

Upvotes: 0

Views: 546

Answers (1)

user2230501
user2230501

Reputation:

The solution was to add the option inside the field structure.

"fields": [{
    "label": "Data",
    "name": "data",
    "type": "autoComplete",
    "opts": {
    "source": ['banana'],
    "minLength": 3
    }

Upvotes: 1

Related Questions