Skip to content

Commit 4ce11dc

Browse files
committed
fix: selector for map->key element
1 parent 360921e commit 4ce11dc

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/utils/settings/types/map.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Translation from 'src/structures/constants/translation.js';
12
import Setting from './array.js';
23

34
export default class MapList extends Setting {
@@ -12,23 +13,25 @@ export default class MapList extends Setting {
1213
/**
1314
* @param {Map<string, string>} val
1415
*/
15-
element(val, update, { container }) {
16+
element(val, update, { container, key: setting }) {
1617
const data = [...val.entries()];
1718
function invalid(text) {
1819
return data.some(([value]) => value === text);
1920
}
20-
function add(value) {
21+
function add(value, i) {
2122
function save(remove) {
2223
if (remove) data.splice(data.indexOf(value), 1);
2324
update(data.filter(([key]) => key));
2425
}
25-
container.append(createItem({ value, save, invalid }));
26+
container.append(createItem({ value, save, invalid, key: `${setting}.${i}` }));
2627
}
2728
data.forEach(add);
29+
let entries = data.length;
2830
return $('<button class="btn btn-success glyphicon glyphicon-plus">').on('click', () => {
2931
const item = ['', ''];
3032
data.push(item);
31-
add(item);
33+
add(item, entries);
34+
entries += 1;
3235
});
3336
}
3437

@@ -46,7 +49,7 @@ export default class MapList extends Setting {
4649
'.btn { padding: 3px 6px; }',
4750
'.item { display: inline-flex; flex-wrap: wrap; align-items: center; padding-top: 5px; width: 100%; }',
4851
'.item > * { margin: 0 5px; }',
49-
'.error *:first-child { border-color: red; }',
52+
'.error [id]:not([id$=".value"]) { border-color: red; }',
5053
'.warning { display: none; color: red; flex-basis: 100%; user-select: none; }',
5154
'.error .warning { display: block; }',
5255
];
@@ -61,6 +64,7 @@ function createItem({
6164
value = ['key', 'value'],
6265
save,
6366
invalid,
67+
key,
6468
}) {
6569
const left = $('<input type="text">').val(value[0]).on('blur', () => {
6670
const newVal = left.val();
@@ -69,20 +73,19 @@ function createItem({
6973
if (isInvalid || newVal === value[0]) return;
7074
value[0] = newVal;
7175
save();
72-
});
76+
}).attr('id', key);
7377
const right = $('<input type="text">').val(value[1]).on('blur', () => {
7478
const newVal = right.val();
7579
if (newVal === value[1]) return;
7680
value[1] = newVal;
7781
save();
78-
});
82+
}).attr('id', `${key}.value`);
7983
const button = $('<button class="btn btn-danger glyphicon glyphicon-trash">').on('click', () => {
8084
save(true);
8185
button.parent().remove();
8286
});
83-
// TODO: translation
8487
const warning = $('<div class="warning clickable">')
85-
.text('Duplicate value, not updated! Click here to reset.')
88+
.text(Translation.Setting('map.duplicate'))
8689
.on('click', () => left.val(value[0])
8790
.parent().removeClass('error'));
8891
return $('<div class="item">').append(left, ' : ', right, button, warning);

src/utils/settings/types/map2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export default class AdvancedMap extends Setting {
9595
left.attr('id', options.key);
9696
simpleLookup = true;
9797
}
98+
if (!right.find(`#${options.key}.value`).length) {
99+
right.attr('id', `#${options.key}.value`);
100+
}
98101
cacheLeftValue();
99102
refresh();
100103
untilClose(`refresh:${key}`, refresh, `create:${key}`);

0 commit comments

Comments
 (0)