0

I want to do 2 things as soon as the input-box gets focus:

  • autocomplete (default dropdown)
  • remove the default-value as

    $(".keywordbox > input").autocomplete({"source":"/nl/video/show-keywords/3", "maxLength" : "10" });
    $(".keywordbox > input").focus(function() {
        if ($(this).val() == $(this).prop("defaultValue")) {
            $(this).val('');
        }
        $(this).trigger('keydown.autocomplete');
    });
    

The autocomplete on focus works fine, except when it is combined with

 $(this).val('');

Anyone suggestions to make this work?

** EDIT **

Seems that autocomplete does not work because the input is empty. Even when there is no placeholder-value set.

What I want is that de autocomplete sets of without giving a value, so that all options (without filtering) can be given.

2 Answers2

0

Try to change like

$(".keywordbox > input").focus(function() {

to

$(".keywordbox > input").keydown(function() {

but it is optinal and for your question try like

if ($(this).val() == $(this).prop("defaultValue")) {
    $(this).val('');
    return false;
}

and better than to put default value add placeholder like

<input placeholder="default value">

SIMPLY GIVE LIKE THIS

$(".keywordbox > input").focus(function() {        
    $(this).trigger('keydown.autocomplete');
});
GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • This does not work. I've tried this. It is because the input has an empty value. – Jelle D'Hulster May 16 '13 at 13:29
  • I've found it: $(".keywordbox > input").autocomplete({"source":"/nl/video/show-keywords/3", "maxLength" : "10", "minLength": "0" }); I found it on: http://stackoverflow.com/questions/1268531/jquery-autocomplete-view-all-on-click – Jelle D'Hulster May 16 '13 at 13:49
0

The solutions is simple ... adding the following code

"minLength": "0"

Then it becomes

$(".keywordbox > input").autocomplete(
     {
     "source":"/nl/video/show-keywords/3", 
     "maxLength" : "10", 
     "minLength": "0" 
 });
ChrisR
  • 14,370
  • 16
  • 70
  • 107