Reputation: 1660
I'm trying to bind a input's value to it's controller's property to keep it updated when the property changes. When the input value has changed, I then need to fire a filter method.
I found some examples, but I'm either doing something wrong or they no longer apply as they are a few months old and Ember has gone through some changes.
JSBin: http://emberjs.jsbin.com/oTiKiDI/1/edit
Upvotes: 0
Views: 1232
Reputation: 26
If you were able to manipulate the this.inputDate
property directly, as you're doing in your jsbin, I believe it wouldn't properly fire any observers when you change the value. So rather than manipulating this.inputDate.anything
, you should this.set('inputDate', [whatever])
.
A Date().getDate()
returns just the day of the month, not any usable proxy to a Date object, and adding 1
to that value will not add one day to your Date()
. I prefer to use http://momentjs.com/ to manipulate dates painlessly and semantically.
http://emberjs.jsbin.com/oKehAYE/3/edit works, and has filterDate
pulled out of the actions hash and turned into an observer. If you uncomment the alert()
line it will do something when the inputDate
changes. It probably doesn't work ideally, since when the page initially renders you have a Date
object, and then once you change it you have a Moment
—you might as well initialize inputDate
with moment(new Date)
—but I leave that as an exercise for the reader.
Upvotes: 1