Polymer use function validation on core-input

怎甘沉沦 提交于 2019-12-11 02:43:58

问题


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?


回答1:


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>  


来源:https://stackoverflow.com/questions/24470576/polymer-use-function-validation-on-core-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!