Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1816 from interactivellama/repeater-combobox-events
Browse files Browse the repository at this point in the history
Repeater combobox events
  • Loading branch information
futuremint committed May 25, 2016
2 parents 2da1dd9 + 094f6d5 commit 63b776e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ define(function (require) {
initRepeater();
});

$('#myRepeater').on('pageChanged.fu.repeater', function (e, data) {
console.log('pagechanged', e, data);
});


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REPEATER w/ actions
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
Expand Down
26 changes: 19 additions & 7 deletions js/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,22 @@
},

doSelect: function ($item) {

if (typeof $item[0] !== 'undefined') {
$item.addClass('selected');
// remove selection from old item, may result in remove and
// re-addition of class if item is the same
this.$element.find('li.selected:first').removeClass('selected');

// add selection to new item
this.$selectedItem = $item;
this.$selectedItem.addClass('selected');

// update input
this.$input.val(this.$selectedItem.text().trim());
} else {
// this is a custom input, not in the menu
this.$selectedItem = null;
this.$element.find('li.selected:first').removeClass('selected');
}
},

Expand Down Expand Up @@ -120,7 +130,8 @@
}, this.$selectedItem.data());
} else {
data = {
text: this.$input.val().trim()
text: this.$input.val().trim(),
notFound: true
};
}

Expand Down Expand Up @@ -232,7 +243,6 @@
}

this.$inputGroupBtn.removeClass('open');
this.inputchanged(e);
} else if (e.which === ESC) {
e.preventDefault();
this.clearSelection();
Expand All @@ -256,8 +266,7 @@
$selected = this.$dropMenu.find('li:not(.hidden):last');
}
}
this.$dropMenu.find('li').removeClass('selected');
$selected.addClass('selected');
this.doSelect($selected);
}
}

Expand All @@ -270,10 +279,13 @@
},

inputchanged: function (e, extra) {
var val = $(e.target).val();
// skip processing for internally-generated synthetic event
// to avoid double processing
if (extra && extra.synthetic) return;
var val = $(e.target).val();
if (extra && extra.synthetic) {
this.selectByText(val);
return;
}
this.selectByText(val);

// find match based on input
Expand Down
9 changes: 5 additions & 4 deletions js/repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
});
this.$prevBtn.on('click.fu.repeater', $.proxy(this.previous, this));
this.$primaryPaging.find('.combobox').on('changed.fu.combobox', function (evt, data) {
self.$element.trigger('pageChanged.fu.repeater', [data.text, data]);
self.pageInputChange(data.text);
self.pageInputChange(data.text, data);
});
this.$search.on('searched.fu.search cleared.fu.search', function (e, value) {
self.$element.trigger('searchChanged.fu.repeater', value);
Expand Down Expand Up @@ -473,13 +472,15 @@
});
},

pageInputChange: function (val) {
pageInputChange: function (val, dataFromCombobox) {
// dataFromCombobox is a proxy for data from combobox's changed event,
// if no combobox is present data will be undefined
var pageInc;
if (val !== this.lastPageInput) {
this.lastPageInput = val;
val = parseInt(val, 10) - 1;
pageInc = val - this.currentPage;
this.$element.trigger('pageChanged.fu.repeater', val);
this.$element.trigger('pageChanged.fu.repeater', [val, dataFromCombobox]);
this.render({
pageIncrement: pageInc
});
Expand Down
19 changes: 12 additions & 7 deletions test/combobox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

define(function(require){
var $ = require('jquery');
var html = require('text!test/markup/combobox-markup.html!strip');
var originalHTML = require('text!test/markup/combobox-markup.html!strip');
/* FOR DEV TESTING - uncomment to test against index.html */
//html = require('text!index.html!strip');
html = $('<div>'+html+'</div>').find('#MyComboboxContainer');
var html = $('<div>'+originalHTML+'</div>').find('#MyComboboxContainer');

require('bootstrap');
require('fuelux/combobox');

module("Fuel UX Combobox");
module("Fuel UX Combobox", {
beforeEach: function () {
html = null;
html = $('<div>'+originalHTML+'</div>').find('#MyComboboxContainer');
}
});

test("should be defined on jquery object", function () {
ok($().combobox, 'combobox method is defined');
Expand Down Expand Up @@ -52,7 +57,7 @@ define(function(require){
test("should not autoselect when no default selection", function () {
var $combobox = $(html).find("#MyCombobox").combobox();
var item = $combobox.combobox('selectedItem');
var expectedItem = { text: '' };
var expectedItem = { notFound: true, text: '' };
deepEqual(item, expectedItem, 'no item selected');
});

Expand Down Expand Up @@ -141,13 +146,13 @@ define(function(require){
.trigger(ENTER_EVENT);
};

test("should respond to keypresses appropriately with filter and showOptionsOnKeypress off", function() {
test("should not select any menu items via keyboard navigation with filter off and showOptionsOnKeypress off", function() {
var $combobox = $(html).find("#MyCombobox").combobox();

userInteracts($combobox);

var item = $combobox.combobox('selectedItem');
var expectedItem = { text:'T' };
var expectedItem = { notFound: true, text:'T' };
deepEqual(item, expectedItem, 'Combobox was not triggered, filter not activated');
});

Expand Down Expand Up @@ -238,7 +243,7 @@ define(function(require){
equal(eventFireCount, 1, 'change event bubbled once');
});

test("should fire changed event - input changed", function () {
test("should fire changed event once when input is changed", function () {
var eventFireCount = 0;
var selectedText = '';

Expand Down

0 comments on commit 63b776e

Please sign in to comment.