LStarky
LStarky

Reputation: 2777

Aurelia binding to computed object properties

I'd like to use repeat.for to bind from 1 to 7 fields to an model whose object has all 6 fields, like this:

<div class="form-group col-sm-2" repeat.for="day of days">
  <label class="control-label">Day ${day}</span></label>
  <input type="text" class="form-control" value.bind="record.day${day} & validate">
</div>

This should allow me to create 5 day entries and bind them to record.day1, record.day2, record.day3, record.day4, record.day5. Or, if I adjust days to 7, it should allow all 7. Or only 2.

The labels work fine, but the value.bind="record.day${day}" is causing an error. Is there a good way to do this?

Upvotes: 0

Views: 392

Answers (1)

mgiesa
mgiesa

Reputation: 1013

You need to reference the day variable directly, like you would if it were plain JavaScript. Like this:

<input type="text" class="form-control" value.bind="record['day' + day] & validate">

Upvotes: 2

Related Questions