mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-31 03:52:01 +08: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
|
||||
.computed({
|
||||
read: target,
|
||||
write: (newValue) => {
|
||||
const currentValue = ko.unwrap(target),
|
||||
write: newValue => {
|
||||
let currentValue = target(),
|
||||
list = ko.unwrap(limitedList);
|
||||
|
||||
if (arrayLength(list)) {
|
||||
if (list.includes(newValue)) {
|
||||
list = arrayLength(list) ? list : [''];
|
||||
if (!list.includes(newValue)) {
|
||||
newValue = list.includes(currentValue, list) ? currentValue : list[0];
|
||||
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' });
|
||||
|
|
Loading…
Reference in a new issue