How to write a Bi-directional Value Converters to input a date with Aurelia

时间:2015-07-08 15:41:29

标签: aurelia aurelia-binding

Following code doesnt work because fromView() is called for each updates, resulting in wrong date construction. What the best solution to use bi-directional filters on dates with aurelia ?

<input type=text" value.bind="date | dateFormat: 'DD/MM/YY'"></input>

import moment from 'moment';
export class DateFormatValueConverter {
   toView(value, format) {
      return moment(value).format(format);
   }
   fromView(str, format){
     return moment(str, format);
   }
}

1 个答案:

答案 0 :(得分:3)

这是一个老问题,但是如果有其他人在想,要改变绑定以重新评估模糊使用:

<pre>

 <input type=text" value.bind="date | dateFormat: 'DD/MM/YY' &
 updateTrigger:'blur'"></input>;

</pre>