lekoala/bootstrap5-autocomplete

Remove Value after Change

Closed this issue · 5 comments

I use this code snipped

new Autocomplete(document.getElementById("username"), {
            server: "....",
            maximumItems: 10,
            liveServer: true,
            onSelectItem: function(data) {
                document.getElementById('userID').value = data.value;
            }
        });

My live server returns this
[{"value":1,"label":"My User"}]

I want userID to be filled with 0 if the user entered is not found or username is changed by the user. UserID should be filled only if the user selects the value from the autocomplete. Is this possible?
Currently userID is filled, but not deleted again.

I've made this very easy to do in https://github.com/lekoala/bootstrap5-autocomplete/releases/tag/1.1.6 where you can simply add a data-hidden-input="true" property
otherwise, you can simply do as you do currently and clear value by listening on the input event

Great. Thank you very much

Maybe an idea for later: Another parameter with two default values

'userId' = 2
'_userId' = 'username'

This would make it easier to insert the first value in a CRUD (in update) without having to specify this via another JS statement.

@KodaCHC why would we need "two" default values? you can already set one as the actual input value
you want to add the value of the hidden input as well? i can add one parameter for that

Thank you very much