JQuery 验证未捕获的类型错误:无法读取未定义的属性“设置" [英] JQuery Validate Uncaught TypeError: Cannot read property 'settings' of undefined

查看:24
本文介绍了JQuery 验证未捕获的类型错误:无法读取未定义的属性“设置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JQuery Mobile 表单上使用 JQuery Validate,该表单有一个列表视图,其中包含一个动态创建的自动完成选项.

I am using JQuery Validate on a JQuery Mobile form that has a listview with an Auto Complete option that is created dynamically.

如果您尝试在自动完成字段中键入内容,一旦验证处于活动状态,我就会收到此错误.

I get this error if you try and type into the auto complete field, once validation is active.

我可以看到问题与 jQuery Mobile 创建的用于保存过滤器输入的表单有关,但我不知道如何阻止 jQuery Validate 验证字段.

I can see that the problem is related to the form that jQuery Mobile creates to hold the filter input but I can not figure out how to stop jQuery Validate from validating the field.

我可以使用JS小提琴

(按验证,然后在过滤器框中输入)

(Press Validate and then type in the filter box)

感谢任何建议

谢谢

<body>
<script>
    jQuery.validator.setDefaults({
        ignore: '[data-type="search"]'

    });
</script>
<form>
    <input required>
    <ul id="ac" data-inset="true" data-filter="true" data-filter-reveal="true" data-filter-placeholder="Search cars...">
        <li><a href="#">Acura</a>

        </li>
        <li><a href="#">Audi</a>

        </li>
    </ul>
    <button onclick="$('#ac').attr('data-role','listview');$('#ac').listview();$('form').validate();">Validate</button>
</form>

推荐答案

您的整个问题都是由 listview() 函数创建的动态 HTML 引起的.检查 DOM 会发现这会动态创建一个新的

容器.由于您已将 listview 放在 容器中,因此您现在将 </form> 嵌套在 code><form></form>,这是非常无效的 HTML,也是 jQuery Validate 插件出乎意料地工作的全部原因.

Your whole problem is being cause by the dynamic HTML that is created by the listview() function. Inspecting the DOM reveals that this dynamically creates a new <form> container. Since you've placed listview within your <form> container, you now have <form></form> nested within <form></form>, which is very invalid HTML, and the whole reason the jQuery Validate plugin is working so unexpectedly.

解决方案是将 listview 元素放在 容器之外.

The solution is to place your listview element outside of your <form> container.

这篇关于JQuery 验证未捕获的类型错误:无法读取未定义的属性“设置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆