mdbootstrap / bootstrap-templates

A collection of free Bootstrap 5 templates.
https://mdbootstrap.com/freebies/
3.07k stars 1.02k forks source link

Can't add Tag that doesn't exist in data source #586

Closed attiqeurrehman closed 2 years ago

attiqeurrehman commented 7 years ago

Hi,

I am trying to maintain grades tag in an application and it works for existing data fetched from the server but when I try to add new it submits the form. I have tried to trap the beforeItemAdd but it doesn't stops there. Here's my code:

var grades = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
            remote: {
                url: '../api/Grades?query=%QUERY',
                filter: function(list) {
                    return $.map(list, function(grade) {
                        return { name: grade.Name, id: grade.Id };
                    });
                }
            }
        });

        grades.initialize();
        var gradesOptions = {
            trimValue: true,
            maxTags: 3,
            freeInput: true,
            itemValue: 'id',
            itemText: 'name',
            typeaheadjs: {
                name: 'grades',
                displayKey: 'name',
                source: grades.ttAdapter()
            }
        };
        $('.grades').tagsinput(gradesOptions);

Any pointers?

Thanks, Attiqe

RedNoo commented 7 years ago

+1

wstaelens commented 3 years ago

same issue. with freeInput: true enabled,

Let's say I want to add non-existing tag "test" but there is already in the dropdownsuggestion one or multiple tags that contain "test" like "retest" then I cannot add the new tag "test", it will always select one from the suggestions dropdown like "retest".