核心输入上的聚合物使用功能验证 [英] Polymer use function validation on core-input

查看:99
本文介绍了核心输入上的聚合物使用功能验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释如何使用这个聚合物元素(导航到验证部分?

 < core-input ... validate =test()error =error in the input>< / test> 

这里是测试的定义:

  function test()
{
return true;
}

这样我总是会收到一些错误信息:inout中的错误。



如何使这件事情成功?

聚合物通常不接受属性中的JavaScript,因此 core-input 不接受 validate =test() $ b

  input.validate = function($ c $> $ c>)语法。您必须直接将方法安装到元素上,如下所示:

){...}

在支持数据绑定的情况下,可以使用发布的 invalid 属性:

 < core-input invalid ={{inputValue |验证}}... 

其中验证是一个接受一个字符串并返回一个布尔值的模型的方法。



例如,在一个元素中:

 < template> 
< core-input invalid ={{inputValue |聚合物({
isInvalid:function(value){return false;}

});
< / script>


Can someone explain me how to use the function validation of this Polymer element (navigate to the "validate" section?

<core-input ... validate="test()" error="error in the input"></test> 

Here is definition of test:

function test()
{
     return true;
}

This way I always get some error message about: "error in the inout".

How can I make this thing work?

解决方案

As a security precaution, Polymer in general doesn't accept JavaScript in attributes. So, core-input doesn't accept validate="test()" syntax. You would have to install the method directly onto the element, like so:

input.validate = function() { ... }

Where data-binding is supported, you can use the published invalid property:

<core-input invalid="{{inputValue | validate}}" ...

where validate is a method on the model that takes a string and returns a boolean.

For example, in an element:

<template>
  <core-input invalid="{{inputValue | isInvalid}}" ...
</template>
<script>
  Polymer({
    isInvalid: function(value) { return false; }
  });
</script>  

这篇关于核心输入上的聚合物使用功能验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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