Skip to content

Instantly share code, notes, and snippets.

@zakmac
Last active October 17, 2016 16:39
Show Gist options
  • Save zakmac/997c53d833dfd4605469544552126575 to your computer and use it in GitHub Desktop.
Save zakmac/997c53d833dfd4605469544552126575 to your computer and use it in GitHub Desktop.
mask input in ember
import Ember from 'ember';
export default Ember.Component.extend({
maskedInput: Ember.computed('unmaskedInput', function() {
let input = Ember.get(this, 'unmaskedInput');
let rx = /[\w]/gi;
return input.replace(rx, function(match, tag, char) {
console.log('*', match, tag, char);
if (tag !== undefined) {
return "";
}
return '*';
});
}),
unmaskedInput: '',
actions: {
focusMaskedInput() {
Ember.$('.unmasked-input', this.$()).focus();
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{input
(action "focusMaskedInput")
class="unmasked-input"
value=unmaskedInput
}}
{{input
(action "focusMaskedInput")
class="masked-input"
value=maskedInput
}}
<label>Your SSN</label><br>
{{masked-input value=userSSN}}
{
"version": "0.10.5",
"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.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment