Skip to content

Instantly share code, notes, and snippets.

@jelhan
Last active September 1, 2018 10:24
Show Gist options
  • Save jelhan/bcf03934667364252e52b21930d664fd to your computer and use it in GitHub Desktop.
Save jelhan/bcf03934667364252e52b21930d664fd to your computer and use it in GitHub Desktop.
so-52126279-input-ddau
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
updateVal(val) {
val = parseInt(val);
if (val >= 0) {
this.set('val', val);
} else {
window.alert('number must not be negative');
this.notifyPropertyChange('val');
}
}
},
val: 0
});
<h1>PoC for <a href="https://stackoverflow.com/questions/52126279/how-to-make-type-number-to-positive-numbers-only-using-ember-js">this questition</a> on StackOverflow</h1>
<p>
Current value: {{val}}<br>
Edit: <input type="number" value={{val}} onchange={{action "updateVal" value="target.value"}} min="0" >
</p>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment