vlio20
vlio20

Reputation: 9295

Polymer use function validation on core-input

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?

Upvotes: 2

Views: 2614

Answers (1)

Scott Miles
Scott Miles

Reputation: 11027

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>  

Upvotes: 2

Related Questions