-
-
Save kumkanillam/d7a931aec5b53bcc0850ca06150b164e to your computer and use it in GitHub Desktop.
valid-number-input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Component.extend({ | |
| tagName:'input', | |
| type:'text', | |
| attributeBindings:['type','value'], | |
| value:Ember.computed('innerValue',{ | |
| get:function(key){ | |
| return this.sanitize(this.get('innerValue')); | |
| }, | |
| set:function (key, value){ | |
| let sanitized = this.sanitize(value); | |
| if(!sanitized){ | |
| return this.get('innerValue'); | |
| } | |
| this.set('innerValue', sanitized); | |
| return sanitized; | |
| } | |
| }), | |
| keyUp:function(){ | |
| let sanitizedValue = this.sanitize(this.$().val()); | |
| if(!sanitizedValue){ | |
| this.$().val(this.get('value')); | |
| return false; | |
| } | |
| }, | |
| sanitize:function(val){ | |
| if (Ember.isPresent(val)) { | |
| let num = Number(val); | |
| if(!Number.isNaN(num)){ | |
| return num; | |
| } | |
| } | |
| return null; | |
| }, | |
| input:function(){ | |
| this.update.bind(this)(); | |
| }, | |
| change:function(){ | |
| this.update.bind(this)(); | |
| }, | |
| update:function(){ | |
| let val = this.$().val(); | |
| this.set('value',val); | |
| (this.get('onUpdate')||Ember.K)(this.get('value')); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle', | |
| x:20, | |
| y:0, | |
| actions:{ | |
| myUpdate:function(newValue){ | |
| this.set('y',newValue); | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.10.4", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.7.0", | |
| "ember-data": "2.7.0", | |
| "ember-template-compiler": "2.7.0" | |
| }, | |
| "addons": {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment