Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeahead will copy value to input element when use with tagsinput #145

Open
suwey opened this issue Aug 4, 2015 · 3 comments
Open

typeahead will copy value to input element when use with tagsinput #145

suwey opened this issue Aug 4, 2015 · 3 comments

Comments

@suwey
Copy link

suwey commented Aug 4, 2015

when use with tagsinput, typeahead will copy the value selected to element.val()

select: function () {
var val = this.$menu.find('.active').data('value');
this.$element.data('active', val);
if(this.autoSelect || val) {
var newVal = this.updater(val);
this.$element
.val('') //change this.displayText(newVal) || newVal => ''
.change();
this.afterSelect(newVal);
}
return this.hide();
},

then tagsinput will have a span and a value in the input

@suwey
Copy link
Author

suwey commented Aug 4, 2015

i work out a fix like this:

select: function () {
var me = this;
var val = this.$menu.find('.active').data('value');
this.$element.data('active', val);
if(this.autoSelect || val) {
var newVal = this.updater(val);
this.$element
.val((function(){ if(!!me.options.noPut){ return ''} else {return me.displayText(newVal) || newVal;}}()))
.change();
this.afterSelect(newVal);
}
return this.hide();
},

and use tagsinput like this:

elem.tagsinput({
typeahead: {
source: function() {
return typeaheadService.mapArray(options.init.source, options.init.sourceKey);
},
noPut: true
}
});

@w3geekery
Copy link

@suwey using bootstrap3-typeahead.js + tagsinput. I've added/edited the code to reflect what you've given, but I get an error:
Uncaught ReferenceError: typeaheadService is not defined

Searching through boostrap3-typeahead.js or tagsinput.js OR even typeahead.bundle.js, I don't find refernce to typeaheadService.

What am I missing?

Cheers,
Clark

@suwey
Copy link
Author

suwey commented Dec 17, 2015

@w3geekery sorry about that. " typeaheadService.mapArray(options.init.source, options.init.sourceKey);" is my own code in project, you may test it like below:

elem.tagsinput({
typeahead: {
source: function() {
return ['aaaa', 'bbb', 'ccc'];
},
noPut: true
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants