提问人:noer 提问时间:11/15/2023 最后编辑:JSON Derulonoer 更新时间:11/15/2023 访问量:20
ng-pattern 将模型更改为 undefined,而不是保留它并不允许提交
ng-pattern change the model to undefined instead of leaving it and not allowing submit
问:
嘿,这是我第一次使用 angular, 我希望有一个带有模式验证的输入, 所以,我把这个输入添加到我的表单中:
<input type="text"
id="id"
name="fieldName"
ng-model="path.to.field"
ng-pattern="/^[^a-z]*$/gm"
/>
但我有两个问题:
我有两个输入监听同一个模型,当你输入无效值时 - 模型变为 undefined,第二个输入也变得 undefined。 在这种情况下,您将在第一个输入中看到无效值,并在第二个输入中看到未定义的值。 此外,您将在第一个输入中看到错误,但在第二个输入中看不到 - 因为它未定义。
我想允许用户将此字段留空,但是当他们输入无效输入并且模型更改为 undefined 时,提交将通过 - 即使他们输入的输入无效。 但他们不知道该值是空的。
答: 暂无答案
评论