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:
and also in this project which is doing similar to format values:
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