Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the minimum length of text so that the knockout autocomplete control is shown?

I am using PerpetuumSoft.Knockout library to bind autocomplete to textbox in my asp mvc application as follow:

var myCustomBinding = "...";
var text = knockoutHtml.Hidden();
text.Items.Add(new KnockoutBindingStringItem("autocomplete", myCustomBinding));

The default behavior of knockout autocomplete is firing the autocomplete field immediately after the first character was typed. I want to customize this behavior to force knockout autocomplete control to fire autocomplete field after 3 characters were typed. I don't want to validate text if there are a minimum of 3 characters typed.

I search similar question but I only need to show autocomplete after the third character was typed I don't need any other custom additional behavior.

What I must bind to knockout autocomplete (in myCustomBinding variable)? How to set the minimum length of search text?

like image 455
ElConrado Avatar asked Oct 21 '25 09:10

ElConrado


1 Answers

$(".buttonclass").typeahead({
    source: function (query, process) {
        //your source code
    },
    items: 10,
    autoSelect: false,
    minLength: 3,
    hint: true, //to highlight matching item
    highlight: true,
    afterSelect: function (item) {
        //your code
    },
    matcher: () => {
        return true;
    },
});
like image 190
Rameshkumar Avatar answered Oct 24 '25 19:10

Rameshkumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!