Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer: Custom filters

Checkout the following example (see console errors): http://jsbin.com/yubujiku/1/edit?html,css,output

I'm trying to use the exact same uppercase filter for data-binding from the Custom Filter docs. According to the docs i am not doing anything wrong: http://www.polymer-project.org/docs/polymer/expressions.html#custom-filters

Is there anything i'm missing here? Is this a Polymer bug?

Thanks in advance :)

like image 391
Jos Gerrits Avatar asked Dec 05 '25 20:12

Jos Gerrits


1 Answers

If you look in the DevTools console, you'll see that you're getting this error: Cannot read property 'toUpperCase' of undefined. To solve it, it looks like you'll need to wrap your filter code in an if block to test for undefined inputs.

upperCaseFilter: function(value) {
  if (value) {
    return value.toUpperCase();
  }
}

Here's the fixed version: http://jsbin.com/yubujiku/2/edit?html,css,output

like image 84
CletusW Avatar answered Dec 08 '25 10:12

CletusW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!