I have a custom view named bootstrapText, like this:
import Ember from 'ember';
export default Ember.TextField.extend({
classNames: ['form-control', 'input-md'],
attributeBindings: ['required'],
required: false,
focusOut: function() {
console.log('focusOut');
if (Ember.isEmpty(this.get('value'))) {
this.set('value', 0);
}
}
});
I'm using from the template this way:
{{view 'bootstrapText' value=numbeOfItems type='number'}}
You see, the type is "number". My observation: Ember TextField's behavior when type is set to 'number' is...: it simply wouldn't assign the inputted value to the bound variable (numberOfItems) if I input unparsable string (e.g.: xyz). So, numberOfItems stays undefined.
The problem is: Ember.TextField does not clear the field in that situation. So, the field keeps showing "xyz".
I want it to be cleared automatically, that's why I implement the focusOut method... where I set the the value to 0. But that's not what I actually want; 0 is not the same as undefined. I want to use 'undefined' as "user hasn't entered anything valid". 0 is a a valid input.
I tried: this.set('value', undefined); ... but of course it has no effect to the display (no change detected; undefined -> undefined).
I tried also: this.set('value', 0); followed by this.set('value', undefined); .... No luck.
Do you know the solution / correct technique for this?
Thanks, Raka
Aucun commentaire:
Enregistrer un commentaire