Skip to content

Commit

Permalink
0.3.2 release: fix new issues with two way binding messing up the ori…
Browse files Browse the repository at this point in the history
…ginal one way binding
  • Loading branch information
pdufour committed Nov 21, 2014
1 parent 14b7432 commit 245b230
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"
Expand Down
12 changes: 7 additions & 5 deletions dist/form-helpers-latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '<div class="select-active"';
html += 'data-value="' + value + '"';
html += 'data-label="' + label + '">';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "",
"name": "form-helpers",
"description": "",
"version": "0.3.1",
"version": "0.3.2",
"homepage": "",
"repository": {
"type": "git",
Expand Down
15 changes: 9 additions & 6 deletions src/fancy_dropdowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ $(document).ready(function() {
ctx.selected = value;
var label = $active.html();

$select.change(function(evt) {
selectionChanged.call(this, ctx, evt);
});

html += '<div class="select-active"';
html += 'data-value="'+ value + '"';
html += 'data-label="'+ label +'">';
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 245b230

Please sign in to comment.