- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Vue 中有一个表单,由于电话号码输入的样式原因,它有一些组合输入。
我的问题是用户必须点击 Tab 键才能转到电话号码的下一个输入字段。
有没有办法检查当前和输入的最大长度,并在满足时转到下一个输入?
<div class="combined-input combined-input--phone" :class="{'error--input': phoneInvalid('patientInformation')}">
<div class="open-parenthesis"></div>
<input type="text" id="phoneArea" maxlength="3" @blur="$v.formData.patientInformation.phone.$touch()" v-model.trim="$v.formData.patientInformation.phone.area.$model">
<div class="close-parenthesis"></div>
<input type="text" id="phoneA" maxlength="3" @blur="$v.formData.patientInformation.phone.$touch()" v-model.trim="$v.formData.patientInformation.phone.a.$model">
<div class="dash"></div>
<input type="text" id="phoneB" maxlength="4" @blur="$v.formData.patientInformation.phone.$touch()" v-model.trim="$v.formData.patientInformation.phone.b.$model">
</div>
最佳答案
很确定这在用户体验方面不被推荐,但这里有一个关于如何实现它的例子:https://codesandbox.io/s/move-to-next-input-on-condition-103b5?file=/src/App.vue
有用代码的主要部分是
focusNextOncePopulated(event, max) {
if (event.target.value.length === max) {
const nextElement = this.$refs?.[`input-${Number(event.target.dataset.index) +1}`]
if (nextElement) nextElement.focus()
}
},
说明:每次输入一个字符时,您都会检查该字段的长度是否达到了您在特定输入上设置的最大值。如果是,并且有与 sibling 相似的输入,则关注它。
添加 debounce
在性能方面,几毫秒也不错。
编辑:为了防止在 DOM 中尝试找到正确的下一个 input
时出现任何问题,我们在每个输入上设置了一些 refs(在 Vue 中推荐的选择一些 DOM 元素的方式)。然后,当我们达到 max
时,我们将当前的输入 data-index
增加 1,这使我们能够转到下一个输入。
PS: ?.
语法是optional chaining , 它可以防止丑陋的代码,并允许在达到 max
后没有下一个 input
时避免错误。
PS:不确定是否有办法直接获取元素的 $refs
是 @input
事件,但如果有,我没有找到了解如何去做。
关于javascript - 转到 maxLength 的下一个输入字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65903746/
我需要以某种方式将模型的 max_length 约束 Hook 到 Form 对象中。 假设我定义了一个带有字段的模型:name = models.CharField(max_length=30)现在
“On input while maxlength is active trigger even if maxlength is reached”,这是on input事件的经典用法。当达到 maxl
我正在尝试配置一个 TextView,它的 maxLines=3 并且它的每一行都有 maxLenght=30。 感谢您的帮助。 最佳答案 您可以对实际的 30 个字符使用 maxWidth 函数(平
在表单组验证中,我尝试应用输入最大长度,但是,这个最大长度取决于表单中的其他操作。如果它们改变,也改变 maxMsgLength 的属性值。 消息:['', Validators.maxLength(
我有一个 iOS 应用程序,我在其中使用 NSInputStream(基于 CFReadStreamRef)从网络套接字读取数据。我不断从服务器获取数据,并不断读取和处理它(使用 read:bytes
我的输入字段包含数字和特殊字符,例如逗号和点在计算字段的 maxLength 时,我想跳过特殊字符。 我不想限制特殊字符。 预期输出应为:- 1,234(总长度:- 4) Userna
我只是在忙着弄清楚 cakephp,看起来它会很有趣。 我有一个表单输入,如下所示: echo $form->input('Campaign.title', array('maxLength'=>'7
旧的 ng-maxlength="5"用于触发字段错误,但会继续允许用户输入。 maxlength="5"似乎在阻止输入。当我的表格上有 novalidate 时,这样做是否有 Angular ?当我
我对 AllenNLP 还很陌生,我目前正在使用它的预训练问答模型。我想知道它是否有 channel 长度限制以确保其性能?我知道 BERT 的最大长度为 512,并且会截断更长的段落。 我在 All
我正在处理 TFS 流程模板的自定义工作项,但收到错误指示我用于组控件的标签超过 MaxLength 值。谁能告诉我我可以贴在群组标签上的最大长度是多少? 最佳答案 如您所见,答案是 80。这是官方文
下面是我在注册和登录表单上使用的代码,限制用户输入有限数量的字符: $( "#limit1" ).attr('maxlength','11').on('input', function() { if
我使用的是 Entity Framework 4.3.1,代码优先,并在 SQL Profiler 中查看正在生成的查询。这是一个例子: 如您所见 - 它将参数指定为 nvarchar(max) 但在
我在互联网上发现输入的最大长度是: 524288 个字符 我找不到有关 textArea 的任何信息。 我需要传递一个最多 1 500 000 个字符的 var,因此我尝试找到类似于输入文本或可用于此
使用 jQuery 版本 1.2.3,我尝试在具有属性“maxlength”的 textarea 元素之后添加节点,但它不起作用: $("textarea[@maxlength]").after("A
我使用 Javascript 添加新的文本字段: var input = document.createElement("input"); input.type = "text"; input.nam
好的,所以我正在构建一个自定义注册页面,当然还涉及到 javascript 输入验证。 在该验证中,我使用了 maxlength 属性来验证输入的长度 - 这是一种双重安全,但很容易获得我认为的元素的
基本上,我正在向所有文本框动态添加 maxLength,但我想向那些没有 maxLength 的文本框添加默认 maxLength属性集。 如何使用 jquery、javascript 完成此操作?
我的 html 页面有问题 这里是页面的简化版本 function maxLength() {
我对 ASP.NET MVC3 客户端验证有一个奇怪的问题。我有以下类(class): public class Instrument : BaseObject { public int Id
我在 Vue 中有一个表单,由于电话号码输入的样式原因,它有一些组合输入。 我的问题是用户必须点击 Tab 键才能转到电话号码的下一个输入字段。 有没有办法检查当前和输入的最大长度,并在满足时转到下一
我是一名优秀的程序员,十分优秀!