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

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

问题描述

我正在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会发现它动态创建了一个新的<form>容器.由于已将listview放置在<form>容器中,因此现在<form></form>嵌套在<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元素放置在<form>容器之外.

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

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

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