Created
August 1, 2016 21:04
-
-
Save sylwiaeb/a89854162b379495a0752849c4c627a8 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains 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.TextField.extend({ | |
size: 69, | |
loadData: function() { | |
// API.loadData.sratata() | |
return 1500; | |
}, | |
saveData(value) { | |
console.log(value); | |
// API.saveData.latatata() | |
}, | |
init() { | |
this._super(...arguments); | |
this.loadData(); | |
}, | |
didInsertElement() { | |
let data = this.loadData().toString(); | |
data = data.replace(/..$/, `.${data.match(/..$/)[0]}`); | |
this.set('value', data); | |
}, | |
focusOut() { | |
let value = this.get('value'); | |
let values; | |
value = value.replace(/,*/g, ''); | |
values = value.split('.'); | |
values[0] = values[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); | |
if (values[0] !== undefined && values[0].length === 0) { | |
values[0] = '0'; | |
} | |
if (values[1]) { | |
values[1] = `.${values[1].substr(0, 2)}`; | |
} else { | |
values[1] = '.00'; | |
} | |
value = values[0] + values[1]; | |
this.set('value', value); | |
this.saveData(value.replace(/,*\.*/g, '')); | |
} | |
}); |
This file contains 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' | |
}); |
This file contains 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