Skip to content

Instantly share code, notes, and snippets.

@dhindurthy
Last active April 1, 2019 16:30
Show Gist options
  • Save dhindurthy/b1824e6b6b2103190ede8666f341868e to your computer and use it in GitHub Desktop.
Save dhindurthy/b1824e6b6b2103190ede8666f341868e to your computer and use it in GitHub Desktop.
comment-box-widget
import Ember from 'ember';
export default Ember.Component.extend({
dataValue:'',
keyDown: function(event){
if(event.keyCode===50 ){
this.set('listVisible', true);
event.preventDefault();
}
},
areaValue:'',
listVisible: false,
actions:{
onListChange: function(value){
this.set('dataValue', value);
// append it to exisiting areaVlaue
let areaValue = document.getElementById("myTextarea").value;
let newAreaValue = areaValue + ' ' + value;
this.set('areaValue', newAreaValue);
this.set('listVisible', false);
document.getElementById("myTextarea").focus()
},
addComment: function(){
if(document.getElementById("myTextarea").value){
this.addComment(document.getElementById("myTextarea").value);
document.getElementById("myTextarea").value = '';
}
},
}
});
import Ember from 'ember';
export default Ember.Component.extend({
change: function(obj){
this.listChange(obj.target.value);
},
didInsertElement(){
document.getElementById("list-input").focus()
},
actions:{}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
commentList : [],
datalist:[{
"value":"Africa",
"label":"Africa"
},{
"value":"Australia",
"label":"Australia"
},{
"value":"Europe",
"label":"Europe"
},{
"value":"Asia",
"label":"Asia"
},{
"value":"America",
"label":"America"
},{
"value":"Antarctica",
"label":"Antarctica"
}],
actions:{
addComment: function(commentValue){
let commentList = this.get('commentList');
commentList.addObject({"name":commentValue});
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function(){
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.comment {
border: 1px solid gray;
border-radius: 15px;
padding: 10px;
}
label {
font-size: 12px;
}
button {
margin-left: 10px;
}
.comments-section {
border: 1px solid gray;
margin-top: 10px;
}
{{yield}}
<form>
<label for="myTextarea"> Enter Comment</label><br>
<textarea id="myTextarea" rows="4" cols="50" value={{areaValue}}></textarea>
<button type="submit" {{action "addComment"}}>Save</button>
{{#if this.listVisible}}
<CbDatalist @datalist={{this.datalist}} @listChange={{action "onListChange"}}/>
{{/if}}
</form>
<section class="comments-section">
<h6>Comments</h6>
{{#each commentList as |comment index|}}
<p class="comment">
{{comment.name}}
</p>
{{/each}}
</section>
{{yield}}
<label for="list-input">Continent</label><br>
<input id="list-input" list="continents">
<datalist id="continents" >
{{#each this.datalist as |item|}}
<option class="option" value={{item.value}}>{{item.label}}</option>
{{/each}}
</datalist>
<CbCommentbox
@datalist={{this.datalist}}
@commentList={{this.commentList}}
@addComment={{action "addComment"}}
/>
import { run } from '@ember/runloop';
export default function destroyApp(application) {
run(application, 'destroy');
}
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes.autoboot = true;
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import { assign } from '@ember/polyfills';
let attributes = assign({ rootElement: '#main' }, config.APP);
setApplication(Application.create(attributes));
start();
{
"version": "0.15.1",
"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.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment