简体   繁体   English

查询 polymer 3 页面中的所有元素(queryselectorall)由于阴影元素而无法工作

[英]query the all elements(queryselectorall) in a page in polymer 3 not working due to shadow element

Previously i used polymer 1, for some custom validation i have used following code with queryselectorAll to get the all invalid elements以前我使用 polymer 1,对于一些自定义验证,我使用以下代码和 queryselectorAll 来获取所有无效元素

            var _formTag = this.$$("request-details").$$("#newForm");
           _array = Array.prototype.slice.call(_formTag.querySelectorAll(":invalid"),0);

now, i am doing upgrade to polymer 3 and it is not working with queryselectorAll since all invalid inputs wrapped now with shadowroot.现在,我正在升级到 polymer 3,它不适用于 queryselectorAll,因为所有无效输入现在都用 shadowroot 包装。 Handling elements one by one using id and traversing through shadow root will be tough since we have more number of on-demand form elements.使用 id 逐个处理元素并遍历 shadow root 将很困难,因为我们有更多的按需表单元素。 Sugget me any idea to get the all invalid elements in page.建议我获取页面中所有无效元素的任何想法。

You can get all elements in that form which needs to be validated and then filter which are invalid as below您可以获取该表单中需要验证的所有元素,然后过滤无效的元素,如下所示

var elements = this.$.newForm._getValidatableElements();
var invalidElements = elements.filter(x => x.invalid);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM