【问题标题】:clicking the form field start inputting/overriding existing value单击表单字段开始输入/覆盖现有值
【发布时间】: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


    【解决方案1】:

    这里需要的称为“改写”,就像插入键一样。

    See here

    【讨论】:

    • 我会试一试,但它似乎与大多数浏览器不兼容。
    猜你喜欢
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多