Skip to content

Commit

Permalink
remove event fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodlopes committed Jul 3, 2017
1 parent b4a595d commit e42a788
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 33 additions & 14 deletions jquery.flexdatalist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Autocomplete input fields, with support for datalists.
*
* Version:
* 2.0.3
* 2.0.4
*
* Depends:
* jquery.js > 1.8.3
Expand Down Expand Up @@ -544,25 +544,40 @@ jQuery.fn.flexdatalist = function (_option, _value) {
return;
}
$li = this.findLi($li);
$this.trigger('before:flexdatalist.toggle', [$li.data('value'), options]);
var index = $li.index(),
data = $li.data(),
action = $li.hasClass('disabled') ? 'enable' : 'disable',
current = _this.fvalue.get();
if ($li.hasClass('disabled')) {

$this.trigger('before:flexdatalist.toggle', [
action,
data.value,
data.text,
options
]);

if (action === 'enable') {
var value = $li.data('value');
current.splice(index, 0, value);
$li.removeClass('disabled');
} else {
current.splice(index, 1);
$li.addClass('disabled');
}

current = _this.fvalue.toStr(current);
_this.value = current;

$this
.trigger('after:flexdatalist.toggle', [$li.data('value'), options])
.trigger('after:flexdatalist.toggle', [
action,
data.value,
data.text,
options
])
.trigger('change:flexdatalist', [
$li.data('value'),
$li.data('text'),
data.value,
data.text,
options
]).trigger('change');
},
Expand All @@ -573,21 +588,25 @@ jQuery.fn.flexdatalist = function (_option, _value) {
$li = this.findLi($li);
var values = _this.fvalue.get(),
index = $li.index(),
options = _this.options.get();
data = $li.data(),
options = _this.options.get(),
args = [
data.value,
data.text,
options
];

$this.trigger('before:flexdatalist.remove', [$li.data('value'), options]);
$this.trigger('before:flexdatalist.remove', args);

var val = values.splice(index, 1);
values = _this.fvalue.toStr(values);
$this[0].value = values;
$li.remove();

$this
.trigger('after:flexdatalist.remove', [$li.data('value'), options])
.trigger('change:flexdatalist', [
$li.data('value'),
$li.data('text'),
options
]).trigger('change');
.trigger('after:flexdatalist.remove', args)
.trigger('change:flexdatalist', args)
.trigger('change');

// For allowDuplicateValues
_values.splice(index, 1);
Expand Down
Loading

0 comments on commit e42a788

Please sign in to comment.