Skip to content

Instantly share code, notes, and snippets.

@macgyver
Last active February 6, 2017 13:12
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 macgyver/65924e88610fe38cbc0300eaf6370012 to your computer and use it in GitHub Desktop.
Save macgyver/65924e88610fe38cbc0300eaf6370012 to your computer and use it in GitHub Desktop.
submit button action fired when form is submitted
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
onSubmitForm: function(){
alert('you submitted form');
}
onClickButton: function(){
alert('you clicked button');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Form submit triggers submit button actions'
});
<form class="form-thing" {{action 'onSubmitForm' on='submit'}}>
focus the input and hit enter:
<input class="form-thing__input">
<br>
<button {{action 'onClickButton'}}>don't click the button</button>
</form>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
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 = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('form-thing', 'TODO: put something here', {
integration: true
});
test('it renders', function(assert) {
assert.expect(0);
this.render(hbs`{{form-thing}}`);
let enterKeyEvent = Ember.$.Event('keydown', {code: 13});
this.$('.form-thing__input')
.focus()
.trigger(enterKeyEvent);
this.on('onClickButton', function() {
assert.ok(false, 'button never got clicked');
});
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment