mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-01 05:22:21 +02:00
Resolve an issue with disabling/enabling instances
This commit is contained in:
parent
620bfeae0d
commit
4193422cf6
|
@ -118,6 +118,7 @@ class Choices {
|
||||||
this._prevState = {};
|
this._prevState = {};
|
||||||
this._currentValue = '';
|
this._currentValue = '';
|
||||||
this._canSearch = this.config.searchEnabled;
|
this._canSearch = this.config.searchEnabled;
|
||||||
|
this._isDisabled = this.config.addItems;
|
||||||
this._isScrollingOnIe = false;
|
this._isScrollingOnIe = false;
|
||||||
this._highlightPosition = 0;
|
this._highlightPosition = 0;
|
||||||
this._wasTap = true;
|
this._wasTap = true;
|
||||||
|
@ -214,7 +215,7 @@ class Choices {
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
if (!this.initialised) {
|
if (!this._isDisabled) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,11 +227,13 @@ class Choices {
|
||||||
this.containerOuter.enable();
|
this.containerOuter.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._isDisabled = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
if (!this.initialised) {
|
if (this._isDisabled) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +245,8 @@ class Choices {
|
||||||
this.containerOuter.disable();
|
this.containerOuter.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._isDisabled = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,9 +200,9 @@ describe('choices', () => {
|
||||||
inputEnableSpy.restore();
|
inputEnableSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('not already initialised', () => {
|
describe('when already enabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = false;
|
instance._isDisabled = false;
|
||||||
output = instance.enable();
|
output = instance.enable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -216,10 +216,10 @@ describe('choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when already initialised', () => {
|
describe('when not already enabled', () => {
|
||||||
describe('containerOuter enabled', () => {
|
describe('containerOuter enabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = true;
|
instance._isDisabled = true;
|
||||||
output = instance.enable();
|
output = instance.enable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ describe('choices', () => {
|
||||||
|
|
||||||
describe('containerOuter disabled', () => {
|
describe('containerOuter disabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = true;
|
instance._isDisabled = true;
|
||||||
instance.containerOuter.isDisabled = true;
|
instance.containerOuter.isDisabled = true;
|
||||||
instance.enable();
|
instance.enable();
|
||||||
});
|
});
|
||||||
|
@ -272,9 +272,9 @@ describe('choices', () => {
|
||||||
inputDisableSpy.restore();
|
inputDisableSpy.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('not already initialised', () => {
|
describe('when already disabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = false;
|
instance._isDisabled = true;
|
||||||
output = instance.disable();
|
output = instance.disable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -288,10 +288,10 @@ describe('choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when already initialised', () => {
|
describe('when not already disabled', () => {
|
||||||
describe('containerOuter disabled', () => {
|
describe('containerOuter disabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = true;
|
instance._isDisabled = false;
|
||||||
instance.containerOuter.isDisabled = true;
|
instance.containerOuter.isDisabled = true;
|
||||||
output = instance.disable();
|
output = instance.disable();
|
||||||
});
|
});
|
||||||
|
@ -305,7 +305,7 @@ describe('choices', () => {
|
||||||
|
|
||||||
describe('containerOuter enabled', () => {
|
describe('containerOuter enabled', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance.initialised = true;
|
instance._isDisabled = false;
|
||||||
instance.containerOuter.isDisabled = false;
|
instance.containerOuter.isDisabled = false;
|
||||||
instance.disable();
|
instance.disable();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue