jQuery-Autocomplete icon indicating copy to clipboard operation
jQuery-Autocomplete copied to clipboard

"setOptions" does not update 'noSuggestionNotice' option

Open StefanFrederiksen opened this issue 7 years ago • 0 comments

So I'm having a problem with dynamically updating the 'noSuggestionNotice' property, since I'm loading the lookup in from ajax, and want to tell the user when it's ready, and when it hasn't been initialized yet.

The problem I'm having is that changing the property using 'setOptions' does not actually change anything, and if I have to change it, it looks like I'll have to completely dispose the autocomplete instance, and re-instance it with the new text.

Here's some dummy code to reproduce it, we can see it gets run after 5 seconds, because the width of the suggestion container actually changes, but the text does not.

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>Devbridge Autocomplete Test</title>
        <style>
            .autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }
            .autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
            .autocomplete-selected { background: #F0F0F0; }
            .autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
            .autocomplete-group { padding: 2px 5px; }
            .autocomplete-group strong { display: block; border-bottom: 1px solid #000; }
        </style>
    </head>
    <body>
        <input type="text" autocomplete="off" />
        
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
            integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
            crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.4.7/jquery.autocomplete.js"></script>
        <script>
            $("input").devbridgeAutocomplete({
                lookup: [],
                showNoSuggestionNotice: true,
                noSuggestionNotice: "From page init"
            });

            setTimeout(function(){
                console.log("Changing devbridge autocomplete...");
                $("input").devbridgeAutocomplete("setOptions", { noSuggestionNotice: "From timeout!", width: 500 } );
            }, 5000);
        </script>
    </body>
</html>

StefanFrederiksen avatar Jun 15 '18 10:06 StefanFrederiksen