bootstrap-ajax-typeahead icon indicating copy to clipboard operation
bootstrap-ajax-typeahead copied to clipboard

Can add target element to callback?

Open liubusian opened this issue 7 years ago • 0 comments

Sometimes it is necessary to change the style under different results, just like success and error

So, I added in: https://github.com/biggora/bootstrap-ajax-typeahead/blob/530ae7f7f6b0a41db79843e0894603afee2601b5/js/bootstrap-typeahead.js#L204

to:

data = that.ajax.preProcess(data, this.$element);

other: https://github.com/biggora/bootstrap-ajax-typeahead/blob/530ae7f7f6b0a41db79843e0894603afee2601b5/js/bootstrap-typeahead.js#L179-L181

var params = this.ajax.preDispatch ? this.ajax.preDispatch(query, this.$element) : {
                    query: query
                };

https://github.com/biggora/bootstrap-ajax-typeahead/blob/530ae7f7f6b0a41db79843e0894603afee2601b5/js/bootstrap-typeahead.js#L106-L110

if (this.options.onSelect) {
      this.options.onSelect({
           value: value,
           text: text
       }, this.$element);
}

Now, I can change icon after loading

preProcess(data, elem){
    if(data.success){
        return data;
    }else{
        $(elem).addClass('valid-error');
    }
}

A little suggestion, Thanks

liubusian avatar Apr 17 '18 08:04 liubusian