Created
December 3, 2017 21:53
-
-
Save lukesargeant/7f9420086e5d2c52b3d0d65628e1adf7 to your computer and use it in GitHub Desktop.
DDAU Input Component
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.Component.extend({ | |
tagName: 'input', | |
attributeBindings: [ 'type', 'value', 'placeholder', 'data-stripe', 'name' ], | |
type: 'text', | |
value: '', | |
caret: 0, | |
input() { | |
let newValue = this.readDOMAttr('value'); | |
let newCaret = this.element.selectionStart; | |
console.log('onInput', newValue, newCaret); | |
this._syncDom(); | |
this.sendAction('update', newValue, newCaret); | |
}, | |
_syncDom() { | |
let oldValue = this.get('value') || ''; | |
let oldCaret = this.get('caret') || 0; | |
this.element.value = oldValue; | |
this.element.setSelectionRange(oldCaret, oldCaret); | |
}, | |
didRender: function() { | |
this.element.value = this.get('value') || ''; | |
let caret = this.get('caret') || 0; | |
this.element.setSelectionRange(caret, caret); | |
}, | |
}); |
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({ | |
actions: { | |
update(newValue, newCaret) { | |
let isValid = newValue.match(/^[\d]*[\.]?[\d]*$/); | |
if (isValid) { | |
this.set('value', newValue); | |
this.set('caret', newCaret); | |
} | |
} | |
} | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
label, input { | |
display: block; | |
box-sizing: border-box; | |
} | |
input { | |
margin: .5em 0; | |
font-size: 16px; | |
padding:.5em; | |
} |
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.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment