From 245b23098bd7e631474081dd3cbf92e08ce4e40a Mon Sep 17 00:00:00 2001 From: Paul Dufour Date: Thu, 20 Nov 2014 22:14:05 -0800 Subject: [PATCH] 0.3.2 release: fix new issues with two way binding messing up the original one way binding --- bower.json | 2 +- dist/form-helpers-latest.js | 12 +++++++----- package.json | 2 +- src/fancy_dropdowns.js | 15 +++++++++------ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bower.json b/bower.json index 3c920a2..4f0c841 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "form-helpers", - "version": "0.3.1", + "version": "0.3.2", "homepage": "https://github.com/britco/form-helpers", "authors": [ "Paul Dufour " diff --git a/dist/form-helpers-latest.js b/dist/form-helpers-latest.js index 23dcb1f..23da20d 100644 --- a/dist/form-helpers-latest.js +++ b/dist/form-helpers-latest.js @@ -107,9 +107,6 @@ $(document).ready(function() { var value = $active.attr("value"); ctx.selected = value; var label = $active.html(); - $select.change(function(evt) { - selectionChanged.call(this, ctx, evt); - }); html += '
'; @@ -142,12 +139,14 @@ $(document).ready(function() { $(".select-wrapper", $parent).on("destroyed" + ns, ctx, divRemoved); $(".select-options li", $parent).on("click" + ns, ctx, clickedItem); $(".select-options", $parent).on("mouseover" + ns, "li", ctx, hoverOverItem); + $select.on("change" + ns, ctx, selectionChanged); }); }; - function selectionChanged(ctx, evt) { + function selectionChanged(evt) { + var ctx = evt.data; var $allSelected = $(this).find(":selected"); var value = $allSelected.attr("value"); - var $selectedOptions = ctx.$options.find("[data-value=" + value + "]"); + var $selectedOptions = ctx.$options.find('[data-value="' + value + '"]'); selectUpdateValue(ctx, $selectedOptions, undefined, false); } function bodyClicked(e) { @@ -178,9 +177,12 @@ $(document).ready(function() { var label = $li.attr("data-label"); var value = $li.attr("data-value"); ctx.$select.val(value); + var ns = ctx.ns; + ctx.$select.off("change" + ns, selectionChanged); if (retrigger !== false) { ctx.$select.trigger("change"); } + ctx.$select.on("change" + ns, ctx, selectionChanged); ctx.selected = value; ctx.$options.find("> li.active").not('li[data-value="' + $li.attr("data-value") + '"]').removeClass("active"); if (typeof flash !== "undefined") { diff --git a/package.json b/package.json index 57f4194..512ac85 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "", "name": "form-helpers", "description": "", - "version": "0.3.1", + "version": "0.3.2", "homepage": "", "repository": { "type": "git", diff --git a/src/fancy_dropdowns.js b/src/fancy_dropdowns.js index 011d40a..1c8c0a4 100644 --- a/src/fancy_dropdowns.js +++ b/src/fancy_dropdowns.js @@ -117,10 +117,6 @@ $(document).ready(function() { ctx.selected = value; var label = $active.html(); - $select.change(function(evt) { - selectionChanged.call(this, ctx, evt); - }); - html += '
'; @@ -165,14 +161,16 @@ $(document).ready(function() { $('.select-wrapper', $parent).on('destroyed'+ns, ctx, divRemoved); $('.select-options li', $parent).on('click'+ns, ctx, clickedItem); $('.select-options', $parent).on('mouseover'+ns, 'li', ctx, hoverOverItem); + $select.on('change'+ns, ctx, selectionChanged); }); }; // Updates the UI whenever the select element changes - function selectionChanged(ctx, evt) { + function selectionChanged(evt) { + var ctx = evt.data; var $allSelected = $(this).find(':selected'); var value = $allSelected.attr('value'); - var $selectedOptions = ctx.$options.find('[data-value=' + value + ']'); + var $selectedOptions = ctx.$options.find('[data-value="' + value + '"]'); selectUpdateValue(ctx, $selectedOptions, undefined, false); } @@ -225,7 +223,12 @@ $(document).ready(function() { // Update original select ctx.$select.val(value); + // Fire a change event, but don't allow **our** onChange event to fire.. that + // is just asking for trouble.. + var ns = ctx.ns; + ctx.$select.off('change'+ns, selectionChanged); if (retrigger !== false) { ctx.$select.trigger('change'); } + ctx.$select.on('change'+ns, ctx, selectionChanged); // Update context with new value ctx.selected = value;