mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 05:52:46 +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._currentValue = '';
|
||||
this._canSearch = this.config.searchEnabled;
|
||||
this._isDisabled = this.config.addItems;
|
||||
this._isScrollingOnIe = false;
|
||||
this._highlightPosition = 0;
|
||||
this._wasTap = true;
|
||||
|
@ -214,7 +215,7 @@ class Choices {
|
|||
}
|
||||
|
||||
enable() {
|
||||
if (!this.initialised) {
|
||||
if (!this._isDisabled) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -226,11 +227,13 @@ class Choices {
|
|||
this.containerOuter.enable();
|
||||
}
|
||||
|
||||
this._isDisabled = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (!this.initialised) {
|
||||
if (this._isDisabled) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -242,6 +245,8 @@ class Choices {
|
|||
this.containerOuter.disable();
|
||||
}
|
||||
|
||||
this._isDisabled = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,9 +200,9 @@ describe('choices', () => {
|
|||
inputEnableSpy.restore();
|
||||
});
|
||||
|
||||
describe('not already initialised', () => {
|
||||
describe('when already enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = false;
|
||||
instance._isDisabled = false;
|
||||
output = instance.enable();
|
||||
});
|
||||
|
||||
|
@ -216,10 +216,10 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when already initialised', () => {
|
||||
describe('when not already enabled', () => {
|
||||
describe('containerOuter enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
instance._isDisabled = true;
|
||||
output = instance.enable();
|
||||
});
|
||||
|
||||
|
@ -232,7 +232,7 @@ describe('choices', () => {
|
|||
|
||||
describe('containerOuter disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
instance._isDisabled = true;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
instance.enable();
|
||||
});
|
||||
|
@ -272,9 +272,9 @@ describe('choices', () => {
|
|||
inputDisableSpy.restore();
|
||||
});
|
||||
|
||||
describe('not already initialised', () => {
|
||||
describe('when already disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = false;
|
||||
instance._isDisabled = true;
|
||||
output = instance.disable();
|
||||
});
|
||||
|
||||
|
@ -288,10 +288,10 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when already initialised', () => {
|
||||
describe('when not already disabled', () => {
|
||||
describe('containerOuter disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
instance._isDisabled = false;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
output = instance.disable();
|
||||
});
|
||||
|
@ -305,7 +305,7 @@ describe('choices', () => {
|
|||
|
||||
describe('containerOuter enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
instance._isDisabled = false;
|
||||
instance.containerOuter.isDisabled = false;
|
||||
instance.disable();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue