AutoComplete openOnFocus new option

AutoComplete openOnFocus new option

keith.abramokeith.abramo Posts: 37Questions: 6Answers: 0

I'm using the datatable editor autoComplete field type plugin. Often times, I want to have the autocomplete open as soon as I focus. I updated the 'create' function to look for a new option called 'openOnFocus' in the plugin located here https://editor.datatables.net/plug-ins/field-type/editor.autoComplete to look like this:

create: function ( conf ) {
    conf._input = $('<input type="text" id="'+conf.id+'">')
        .autocomplete( conf.opts || {} );

    //Jquery UI default minlength
    var defaultOptsMinLength = 1;

    // Decide if a min length was passed in. If not, use default.
    var minLength = conf.opts && conf.opts.minLength;
    if (minLength == null) {
        minLength = defaultOptsMinLength;
    }

    if (conf.openOnFocus && conf._input.val().length >= minLength) {

        // Search and display results as soon as focus is detected on input
        conf._input.focus(function () {
            $(this).data("uiAutocomplete").search($(this).val());
        });
    }

    return conf._input[0];
},

Would this be something we could get added to the plugin? How do we request changes to the code? Is that a thing datatables is open to? I'm not sure where else to post this change request.

Thanks!

Replies

  • keith.abramokeith.abramo Posts: 37Questions: 6Answers: 0

    Modified code slightly:

    create: function ( conf ) {
        conf._input = $('<input type="text" id="'+conf.id+'">')
            .autocomplete( conf.opts || {} );
    
        //Jquery UI default minlength
        var defaultOptsMinLength = 1;
    
        // Decide if a min length was passed in. If not, use default.
        var minLength = conf.opts && conf.opts.minLength;
        if (minLength == null) {
            minLength = defaultOptsMinLength;
        }
    
        // Search and display results as soon as focus is detected on input
        conf._input.focus(function () {
    
            if (conf.openOnFocus && $(this).val().length >= minLength) {
                $(this).data("uiAutocomplete").search($(this).val());
            }
        });
    
        return conf._input[0];
    },
    
  • allanallan Posts: 61,686Questions: 1Answers: 10,100 Site admin

    Hi,

    I don't see an option for auto show in the jQuery UI AutoComplete documentation. It looks like applying a search like in your second post is probably as good as it gets.

    Allan

This discussion has been closed.