Created
June 22, 2016 15:56
-
-
Save shoxter/8eda979f6c533e23e2fc4abdd10cca37 to your computer and use it in GitHub Desktop.
Bug
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', | |
oldLength: 0, | |
tempValue: '', | |
actions: { | |
changeValue: function(e) { | |
var input = e.target.value; | |
input = input.replace(/[^\d\(\) -]/g, ''); | |
input = input.substr(0, 14); | |
if (input.length < this.get('oldLength')) { | |
switch (input.length) { | |
case 0: | |
this.set('tempValue', ''); | |
break; | |
case 1: | |
this.set('tempValue', ''); | |
break; | |
case 6: | |
this.set('tempValue', input.substr(0,4)); | |
break; | |
case 10: | |
this.set('tempValue', input.substr(0,9)); | |
break; | |
default: | |
this.set('tempValue', input); | |
} | |
} else { | |
switch (input.length) { | |
case 0: | |
this.set('tempValue', ''); | |
break; | |
case 1: | |
this.set('tempValue', '(' + input); | |
break; | |
case 4: this.set('tempValue', input + ') '); | |
break; | |
case 9: | |
this.set('tempValue', input + '-'); | |
break; | |
case 15: | |
this.set('tempValue', this.get('tempValue')); | |
break; | |
default: | |
this.set('tempValue', input); | |
} | |
} | |
this.set('oldLength', this.get('tempValue.length')); | |
} | |
} | |
}); |
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.9.3", | |
"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.6.0", | |
"ember-data": "2.6.1", | |
"ember-template-compiler": "2.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment