0

I am not sure if this is a bug or i am doing something wrong.

I have 6 properties

(function () {
  Polymer({
    is: 'claim-type',
      properties: {
        foo: {
          type: Number,
          value: false,
          observer: 'add'
        },
        bar: {
          type: Number,
          value: false,
          observer: 'add'
        },
        ....

and so on....

Each one is linked to a

When one changes it triggers the observer 'add'

add: function () {
  this.ray = this.bar + this.foo + this.etc;
}

say foo = 1 and bar = 2 and etc = 3

the result will equal 123 instead of 6?

What am i doing wrong?

EDIT: changed code from type Boolean to Number

Ben Thomas
  • 3,180
  • 2
  • 20
  • 38
PSVapour
  • 33
  • 6
  • How are `bar`, `foo` and `etc` being changed? Is it by user input? – Ben Thomas Sep 03 '15 at 14:28
  • Yes user input, figured it out. It was treating them as string! I had a bit of a moment! Eeeaaak!! Added a + to the start of this.foo so +this.foo + +this.bar – PSVapour Sep 03 '15 at 14:34

1 Answers1

1

Polymer seems to be treating the Numbers as strings. This is probably do to the fact it is using paper-input

need to add the + sign in front of the variable to convert it into a number.

add: function () {
  this.ray = +this.bar + +this.foo + +this.etc;
}
PSVapour
  • 33
  • 6