Why is `<select multiple` bound to `string[]`? (solved)

Hi there,

I have a question. Maybe this is a bug as well, since behavior is different than Aurelia v1.

When binding number[] to <option> elements, upon user making a selection, selected values turn into an array of string (string[]).

So, for example, options are bound to [1, 2, 3, 4, 5]. User selects 1 and 4, selected value (on <select> element is ['1', '4'].

There is a StackBlitz example. Two dropdowns:

  • First one is bound to numbers in the template using value.one-time.
  • Second one is bound to an array defined as a property of a component.

I also noticed another “quirk” - properties to which select elements are bound have to be initialized upfront to an empty array [], otherwise interpolation binding to display values does not work. This happens even in simplest a possible example:

Again, in Aurelia v1, this would work.

OK, my bad. when model.bind is used on <option> element array contains numbers, not strings (number[])

1 Like