tweak some code for mask input option

This commit is contained in:
Yanzhen Yu
2019-06-15 14:38:03 +08:00
parent 189df87b9d
commit a51313d973
2 changed files with 25 additions and 6 deletions

View File

@@ -379,7 +379,21 @@ function initViewportResizeObserver(
}
const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
const MASK_TYPES = ['color', 'date', 'datetime-local', 'email', 'month', 'number', 'range', 'search', 'tel', 'text', 'time', 'url', 'week']
const MASK_TYPES = [
'color',
'date',
'datetime-local',
'email',
'month',
'number',
'range',
'search',
'tel',
'text',
'time',
'url',
'week',
];
const lastInputValueMap: WeakMap<EventTarget, inputValue> = new WeakMap();
function initInputObserver(
cb: inputCallback,
@@ -406,10 +420,12 @@ function initInputObserver(
}
let text = (target as HTMLInputElement).value;
let isChecked = false;
const hasTextInput =
MASK_TYPES.includes(type) || (target as Element).tagName === 'TEXTAREA';
if (type === 'radio' || type === 'checkbox') {
isChecked = (target as HTMLInputElement).checked;
} else if ((MASK_TYPES.indexOf(type) >= 0 || (target as Element).tagName == 'TEXTAREA') && maskAllInputs) {
text = Array(text.length+1).join('*')
} else if (hasTextInput && maskAllInputs) {
text = '*'.repeat(text.length);
}
cbWithDedup(target, { text, isChecked });
// if a radio was checked