【发布时间】:2021-12-03 22:42:58
【问题描述】:
我被要求执行以下操作:
允许用户单击字段中的任意位置并开始输入,然后在他们输入时覆盖数字。
当用户单击他们尝试重新输入修改后的数字的数字旁边时,我的解决方案有效。我认为这在 UI 实践中是相当标准的。有没有人解决如何实现粗体区域中的要求,通过单击该字段更新电话号码字段,然后开始输入/覆盖。?
//have an observer on the following function:
static get observers() { return [
_workNumber(_contract.workPhone),
}}
_workNumber(str) {
let cleaned = ('' + str).replace(/\D/g, '');
let match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
if (match) {
//the binding value in the input tag in HTML.
this._contract.workPhone = '(' + match[1] + ') ' + match[2] + '-' + match[3];
return '(' + match[1] + ') ' + match[2] + '-' + match[3]
};
return null
};
【问题讨论】:
标签: javascript forms input