Skip to content

Instantly share code, notes, and snippets.

@HeroicEric
Last active December 13, 2018 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeroicEric/378bd451645888fd7ec89fdfd5402cdc to your computer and use it in GitHub Desktop.
Save HeroicEric/378bd451645888fd7ec89fdfd5402cdc to your computer and use it in GitHub Desktop.
Name editor p2
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
tagName: '',
value: null,
firstName: Ember.computed('value', function() {
return (this.value || '').split(' ')[0];
}).readOnly(),
lastName: Ember.computed('value', function() {
return (this.value || '').split(' ')[1];
}).readOnly(),
setFirstName(value) {
let fullName = [value, this.lastName].join(' ');
this.onChange(fullName);
},
setLastName(value) {
let fullName = [this.firstName, value].join(' ');
this.onChange(fullName);
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
fullName: 'Tom Dale',
setFullName(value) {
this.set('fullName', value);
}
});
<h1>{{fullName}}</h1>
<h3>Without block</h3>
<NameEditor @onChange={{action setFullName}} @value={{fullName}} />
<h3>With block</h3>
<NameEditor @onChange={{action setFullName}} @value={{fullName}} as |Editor|>
<Editor.firstName />
<Editor.lastName />
</NameEditor>
<label>First name:</label>
<input
value={{@value}}
oninput={{action @onChange value="target.value"}}
>
<label>Last name:</label>
<input
value={{@value}}
oninput={{action @onChange value="target.value"}}
>
{{#if hasBlock}}
{{yield (hash
firstName=(component "firstNameEditor"
onChange=(action this.setFirstName)
value=this.firstName
)
lastName=(component "lastNameEditor"
onChange=(action this.setLastName)
value=this.lastName
)
)}}
{{else}}
<FirstNameEditor
@onChange={{action this.setFirstName}}
@value={{this.firstName}}
/>
<LastNameEditor
@onChange={{action this.setLastName}}
@value={{this.lastName}}
/>
{{/if}}
{
"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