mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Improved ko.extenders.limitedList
This commit is contained in:
parent
1d63683cf9
commit
0bf891ba9d
1 changed files with 13 additions and 21 deletions
22
dev/External/ko.js
vendored
22
dev/External/ko.js
vendored
|
|
@ -156,23 +156,15 @@ ko.extenders.limitedList = (target, limitedList) => {
|
||||||
const result = ko
|
const result = ko
|
||||||
.computed({
|
.computed({
|
||||||
read: target,
|
read: target,
|
||||||
write: (newValue) => {
|
write: newValue => {
|
||||||
const currentValue = ko.unwrap(target),
|
let currentValue = target(),
|
||||||
list = ko.unwrap(limitedList);
|
list = ko.unwrap(limitedList);
|
||||||
|
list = arrayLength(list) ? list : [''];
|
||||||
if (arrayLength(list)) {
|
if (!list.includes(newValue)) {
|
||||||
if (list.includes(newValue)) {
|
newValue = list.includes(currentValue, list) ? currentValue : list[0];
|
||||||
|
target(newValue + ' ');
|
||||||
|
}
|
||||||
target(newValue);
|
target(newValue);
|
||||||
} else if (list.includes(currentValue, list)) {
|
|
||||||
target(currentValue + ' ');
|
|
||||||
target(currentValue);
|
|
||||||
} else {
|
|
||||||
target(list[0] + ' ');
|
|
||||||
target(list[0]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
target('');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.extend({ notify: 'always' });
|
.extend({ notify: 'always' });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue