0
votes

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?

1
Try record['day' + day]mgiesa
That worked perfectly! Thank you!LStarky
Great, I added it as an answermgiesa

1 Answers

2
votes

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">