The following is what I have so far. The problem is that if number-input
is bound to an async
ember-data model property (which will return a promise the frist time an resolve later) - the code below does not work and displays a zero instead.
How can I get it promise aware?
USAGE: (In this case vehicleService is {async : true})
{{number-input numberValue=model.vehicleService.cost}}
CODE:
import Ember from 'ember';
var DELETE_KEY = 46;
var INSERT_KEY = 45;
var ZERO_KEY = 48;
var NINE_KEY = 57;
export default Ember.TextField.extend({
tagName: 'input',
type: 'number',
numberValue: function(key, value) {
if (arguments.length === 1) {
var number = parseFloat(this.get('value'));
return isNaN(number) ? 0 : number;
} else {
return this.set('value', (value !== void 0 ? '' + value : ''));
}
}.property('value'),
didInsertElement: function() {
return this.$().keypress(function(key) {
if ((key.charCode !== DELETE_KEY) && (key.charCode !== INSERT_KEY) && (key.charCode < ZERO_KEY || key.charCode > NINE_KEY)) {
return false;
}
});
}
});