Hello,

I have a custom element that I need to pass a function to for formatting a 
value differently depending how it is being used. I am trying to do the 
following:

*<my-element field="date" formatter="[[dateFormatter]]"></my-element>*

where* dateFormatter* is defined on a parent element that creates the 
*<my-element>* instances, accessible from the parent element using* 
this.dateFormatter*.

My assumption was that when I call:
*Polymer.dom(this.root).querySelector("my-element").getValue(new Date()); *

my-element would run the date instance through it's* this.formatter* 
function that I had specified. 

Internally in my-element, I am doing the following in *getValue()*:
*[ ... ]*
*getValue: function(value) {*
*  if ("formatter" in this) {*
*    return this.formatter(value);*
*  }*
*  return value;*
*}*
*[ ... ]*

However *this.formatter* is always undefined. 

I realize that the allowed property types are Boolean, Date, Number, 
String, Array or Object, though I see Function used successfully in 
dom-repeat:
https://github.com/Polymer/polymer/blob/edb59eb6283074ce54f374b30b884c9f9fcf9f5f/src/lib/template/dom-repeat.html#L168
and also in this project which is doing similar to format values:
https://github.com/David-Mulder/paper-datatable/blob/master/paper-datatable-column.html#L187
 - where the formatValue function is 
defined: 
https://github.com/David-Mulder/paper-datatable/blob/master/demo/paper-datatable/filter.html#L86

Is there something I'm missing? Is there a better way of doing this? This 
element will be reused all over our webapp, so it's impossible for me to 
know exactly how these values will be formatted. 

Thanks

Follow Polymer on Google+: plus.google.com/107187849809354688692
--- 
You received this message because you are subscribed to the Google Groups 
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/e8d93a6a-907c-40f6-b349-924afe564956%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to