From 79eef9973150c1458c6ac451d10e6e918072739b Mon Sep 17 00:00:00 2001 From: Keegan Date: Fri, 11 Mar 2016 03:57:30 +1100 Subject: [PATCH] Fix events firing on wrong element for button component --- src/scripts/lib/clay-item.js | 2 +- src/templates/components/checkboxgroup.tpl | 1 - src/templates/components/radiogroup.tpl | 1 - test/spec/components/index.js | 15 +++++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/scripts/lib/clay-item.js b/src/scripts/lib/clay-item.js index 3d38138..c3ad27f 100644 --- a/src/scripts/lib/clay-item.js +++ b/src/scripts/lib/clay-item.js @@ -59,7 +59,7 @@ function ClayItem(config) { }; // attach event methods - ClayEvents.call(self, self.$element); + ClayEvents.call(self, self.$manipulatorTarget); // attach the manipulator methods to the clayItem _.eachObj(_component.manipulator, function(methodName, method) { diff --git a/src/templates/components/checkboxgroup.tpl b/src/templates/components/checkboxgroup.tpl index 2a7906b..6f7c15c 100755 --- a/src/templates/components/checkboxgroup.tpl +++ b/src/templates/components/checkboxgroup.tpl @@ -8,7 +8,6 @@ type="checkbox" value="{{this.value}}" name="clay-{{clayId}}" - data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}} /> diff --git a/src/templates/components/radiogroup.tpl b/src/templates/components/radiogroup.tpl index 48c15b9..f2e4ba8 100755 --- a/src/templates/components/radiogroup.tpl +++ b/src/templates/components/radiogroup.tpl @@ -8,7 +8,6 @@ type="radio" value="{{this.value}}" name="clay-{{clayId}}" - data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}} /> diff --git a/test/spec/components/index.js b/test/spec/components/index.js index b916c45..f077c57 100644 --- a/test/spec/components/index.js +++ b/test/spec/components/index.js @@ -7,6 +7,7 @@ var HTML = require('../../../src/scripts/vendor/minified').HTML; var components = require('../../../src/scripts/components'); var manipulators = require('../../../src/scripts/lib/manipulators'); var fixture = require('../../fixture'); +var sinon = require('sinon'); var componentSchema = Joi.object().keys({ name: Joi.string().required(), @@ -39,6 +40,20 @@ describe('components', function() { it('is able to be passed to ClayConfig', function() { fixture.clayConfig([component.name]); }); + + it('only has one $manipulatorTarget', function() { + var configItem = fixture.clayConfig([component.name]).getAllItems()[0]; + assert.strictEqual(configItem.$manipulatorTarget.length, 1); + }); + + it('only dispatches change events once', function() { + var configItem = fixture.clayConfig([component.name]).getAllItems()[0]; + var handler = sinon.spy(); + configItem.on('change', handler); + configItem.trigger('change'); + assert.strictEqual(handler.callCount, 1); + }); + }); }); });